I'm looking at ECS with four private subnets and the NAT gateway costs add up quickly. Is there a cheaper way to give tasks outbound access without making the setup too fragile?
How can I bring down NAT costs for a small ECS setup?
Answers
You don't necessarily need one NAT gateway per subnet. Private subnets can route through a shared gateway, so check the route tables before paying for four.
The tradeoff is availability. If subnets in different Availability Zones share one gateway, an outage in its zone can affect outbound access from the others. Cross-zone traffic can also add transfer charges. Compare that with a gateway per zone, not just the gateway hourly price.
Reply to this answer
For a small workload, fck-nat on an EC2 instance is worth considering. One setup in the discussion used a t3.micro and reported reducing monthly NAT costs from $177 to $7. That number depends on instance pricing, traffic and the rest of the network, so don't treat it as a quote for your setup.
The catch is that you're replacing a managed service with an instance you need to maintain. Put it in an Auto Scaling group with a desired capacity of one if automatic replacement is useful, but expect an interruption while a failed instance is replaced. Check how the route and any fixed public IP will be restored when that happens.
Reply to this answer
Look at where the traffic goes before choosing a NAT setup. An S3 gateway endpoint has no endpoint charge and can keep S3 traffic off the NAT path. ECR image layers are stored in S3, so that can help with image pulls too.
There are also interface endpoints for services such as ECR and CloudWatch Logs. Those have their own charges, so compare them with the NAT processing costs they would avoid rather than assuming they'll always save money.
Reply to this answer
Check whether the tasks and everything they need to reach can use IPv6. That may reduce or remove the need for IPv4 NAT, but it isn't automatic just because ECS supports IPv6. Dependencies and outbound routing still need to work with it.
Reply to this answer
Add your answer
Answers are reviewed before publication.
_f63~zeldrivo.4:
Also check whether anything outside AWS expects a specific source IP. A replacement instance needs the address reattached if that allowlist is going to keep working.