I have a simple project consisting of a single AZ RDS, a Single API ECS Task in Fargate and a EC2 instance for bastion accessible via SSM. The content of the application (html, angular) is pushed to cloudfront.
I have been trying to figure out why my VPC charges were so high, with most of the charges been the `DescribeNetworkInterfaces` API call? It was .72/day for April. So 6 IPs a day?
Does this mean that any service obtaining an IP from any of the subnets will also get a public IP address as well even if it’s not needed? Does turning this off still allow things like the ECS Fargate instance to have a public IP address and internet access so it can get the containers, since I am not using NAT or VPC Endpoints?
I think my ideal situation would be to have everything on private subnets with only the load balancer having public IPs. The only way I can achieve that is to use NAT or setup endpoints for the various services (SSM on bastion host and ECR/S3 for the ECS Fargate Task). Using the public IPs and GW is a simpler solution for now and likely has less cost than a NAT gateway or setting up the endpoints.
Yes that’s best practice, keep everything in private subnets, and turn off auto assign public IP in subnet settings, and just have a load balancer serving 2+ subnets across separate availability zones for HA
Also you don’t need to use NAT gateway for low volume, find a verified NAT image from public AMIs and deploy one or more EC2s using that, then point your route table to that, remember you have to disable the source/dest check on the instance for it to work.
Bastion isn’t really needed these days, as you can remote directly on using SSSM session manager from the console, once you configure it, so you can just remote into the real EC2S etc
Right, but then those things in the private subnets need things like S3, ECR, Cloudwatch for the FARGATE task and then SSM for the EC2 instance which allows me to connect to the DB remotely.
So, with that either need to setup NAT or the VPC Endpoints.
Right now, I think I can get away with 4 IPs:
1 IP for the EC2 instance which allows access to SSM.
1 IP for the Fargate Task (to allow ECR, CloudWatch, S3)
2 IP for the load balancer (one IP in each of the 2 AZ)
So, it comes down to a cost optimization problem to solve. The public IPs cost $14.40/mo ($0.005/hr*24hours*30days*4ips).
I think the cost for the private endpoints for all the various services would end up being more expensive. I think the next best solution would be to roll my own EC2 instance with a NAT or just use a AWS NAT.
Well you can setup an s3 Gateway endpoint, they are free and any traffic and forth is also free of charge, you just need to edit the route table to point stuff to the pl
You don’t need endpoints for the rest, they will all go out via a NAT and route via Internet
You should have everything behind a NAT instance/gateway, it’s bad security practice to run everything public.. As I mentioned there are pre canned hardened NAT instances available to you, just search public AMIs
I now have 6 subnets, 3 private & 3 public. I have a EC2 NAT instance running and the private subnets have their default route over to that interface. The ECS instances, RDS all live on the 3 private instances.
I also switched over from using SSM to the new EC2 connect. So sweet.
I cleaned a bunch of the TF up and don’t rely on the default VPC anymore.
I removed a bunch of mystery between private and public subnets. I always thought there was something different between them, but its really just the default route which matters.
I will now work on tightening up some of the SGs but I’m happy!
Generally the hardened NAT instance AMIs get updated each month, so you can simply re deploy a new one, or you can setup system manager patching to automate scheduled patching on whichever schedule you prefer and just keep the existing deployment up to date that way