- Newest
- Most votes
- Most comments
From the security standpoint, you should not keep your ECS Fargate Service tasks inside public subnet.
Here is what you can do:
- Run your Amazon ECS task on Fargate in a private subnet. Refer this to learn how to do it.
- Putting ECS Task inside private subnet will not allocate them a public IP, and will block their internet access.
- Use NAT Gateway or NAT Instance in public subnet, update Route Table associated with Private Subnet to redirect internet traffic originating from private subnet to NAT GW or NAT Instance in public subnet. Refer this to learn how to do it.
- Attach Elastic IP to your NAT Gateway or NAT Instance. Refer this to learn how to do it.
This will not only solve your static IP purpose, but also enhance security for your containers as they will be running inside private subnet.
You need to ensure your ECS services are attached to a Private Subnet with routes to a NAT Gateway. Ensure you have multiple NAT gateways spread across the region.
If in eu-west-2, create 3 NAT gateways, 1 on each of the 3 Public Subnets. Each public subnet has a route to the IGW.
NAT Gateways are assigned a public IP Address each. Supply the 3rd Party the 3 x NAT Gateway IP Addresses. Any traffic destined to the internet will come from one of the 3 NAT Gateway IP's
A NAT gateway provides internet access from ECS
Relevant content
- asked 2 years ago
- Accepted Answerasked 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
We require internet access for the ECS service as it will be utilized in a client application. Consequently, we've integrated an ALB (Application Load Balancer) with an HTTPS listener into the ECS service. Our VPC is already established with a NAT gateway, but we could benefit from additional information regarding its usage.
I did not get to any point of conclusion from your recent comment. What is blocking you to run your containers inside private subnet and accessing internet via NAT Gateway?