I want to have this simple configuration.
A VPC with 2 subnets:
A) public subnet with an nginx server that routes to my private subnet. This is made public with an internet gateway and a configured route table
B) private subnet with another ec2 instance running some python server (just a “hello world” server for this example, but it will eventually be an api with logic)
The public one is easy enough to configure, since it’s made public with its route table, I can’t ssh into it and make any modifications I need to.
However the private one, how does this get configured/code updated/etc without being able to ssh into it? I was thinking of first making it public, make my configurations/changes/ start the web service, then make it private. But this is tedious if i have to do it every time.
Look into Systems Manager specifically Session manager. You can actually access it from the ec2 screen. If you click connect there should be a tab for it.
You can use a pipeline to build and deploy code to your EC2 instance.
Create a Code Pipeline that get’s triggered on push to your github repo, build your project, and then deploy the artifact to EC2.
Even though your EC2 instance is in a private subnet, other AWS resources can communicate with it, either because the Code Deploy agent in running on the EC2 instance or through ECS if you are using ECS EC2.
One thing cool about SSM is you can forward local ports too. Similar to kubectl port-forward. Very handy for connecting to private services for testing/vslidation/debugging.
If you’re running apps in the cloud 100% should not be provisioning by hand.
This would be the way to go ^^^
But you can also do a bastion set up if you REALLY want to provision by hand Or use something like ansible. I think ansible can use SSM as well not 100% on that though.
yeah, you can get a shell on the instance with aws ssm start-session --target i-xxxxxxxxxxxxxxxxx, instance also need the ssm agent and certain permissions
You still need the private instance to be able to reach the AWS ssm endpoints. If the instance can’t reach it will not work either.
If your nginx is reachable with ssh from the internet you can use it as a jump server into the private box. Just make sure you specify the right public key while spawning it.
When you ssh into your nginx box you can tell ssh to add your private key to it so you can jump fron the nginx box to the backend machine https://docs.github.com/en/authentication/connecting-to-github-with-ssh/using-ssh-agent-forwarding
I reread your comment and I did misread it the first time.
Yes, it still needs egress to the services or vpc endpoints. Also needs ssm agent, permissions and such. I just didn’t want to give step by step on how to set it up. Good point though.
Typically people used to have a bastion server in the public subnet and there is a route enabled from the bastion to the private server. So you ssh into bastion from the outside and then ssh from the bastion onto the server in the private subnet. There are better ways to do that though on ec2 now as others have mentioned because it’s not the most secure, although you could do various things like have a security group rule to only allow connections into bastion from your IP or something.
Using the SSM Document AWS-StartSSHSession is really all you need, because with that you can use SSH not only to start an ssh terminal session but also to do port forwarding and scp
You’d set this up with your routing tables inside the VPC. I don’t have a CF template handy because mobile, but that’s what you want to Google. Two subnets with the private one egressing through the public one.
Alternatively, an ALB in front of your EC2 box might be a good approach. You wouldn’t have to worry about scaling your nginx capacity, and if you need to add more compute to your app, you can stand up more EC2 boxes and use the ALB to round-robin through your servers.
As others have written: SSM or CloudShell is a quick solution.
You could also create a VPN to your home network, e.g. with TailScale like I did here. With that I can connect from home directly to my private subnet.