"Private subnets can't reach the internet." They can, with NAT. Servers in private subnets still need operating system updates, package downloads and outside APIs. NAT lets them start connections to the outside while nothing outside can start a connection to them. AWS gives you two ways to run it, and the choice affects both your uptime and your bill.
What NAT does
NAT stands for network address translation. A NAT device sits between the private resources in your VPC and the internet. When a private server calls out, the NAT device replaces the server's private address with its own, sends the request on, and passes the reply back to the right server.
The setup has three parts:
- The NAT device lives in a public subnet and has a public address.
- The private subnet's route table sends internet-bound traffic (
0.0.0.0/0) to the NAT device. - Connections must start from inside. Unsolicited inbound connections are not passed through.
NAT gateway: the managed option
A NAT gateway is a service AWS runs for you. According to the AWS comparison:
- Availability: each NAT gateway is implemented with redundancy inside its Availability Zone.
- Bandwidth: it scales up to 100 Gbps.
- Maintenance: none. AWS manages it.
A standard (zonal) NAT gateway lives in one Availability Zone. If that zone has a problem, private subnets in other zones that depend on it lose their way out. So for resilience, AWS recommends a NAT gateway in each Availability Zone you use, with each private subnet routing to the one in its own zone.
AWS has also added a regional availability mode: a single NAT gateway that automatically expands across the Availability Zones where you have workloads and doesn't need a public subnet to host it. It's newer, so check its current limits before relying on it.
NAT instance: the do-it-yourself option
A NAT instance is an ordinary EC2 instance that you configure to perform NAT. Everything is your job:
- patching the operating system
- choosing an instance type big enough for your traffic
- scripting failover to a second instance if the first one fails
AWS's old ready-made NAT AMI was built on an Amazon Linux version that reached end of maintenance support on December 31, 2023. AWS recommends NAT gateways, and migrating to one if you run a NAT instance today.
The cost trade-off
A NAT gateway is charged for every hour it exists and for every gigabyte it processes, in addition to normal data transfer charges. Rates vary by Region, so check the Amazon VPC pricing page.
A NAT instance costs only the EC2 instance and its data transfer, which can be much less for a small development environment. The price is operational risk: one server that all outbound traffic depends on. A reasonable rule is NAT gateways for production, and a NAT instance only where an outage is acceptable.
Where AI fits
AI workloads move a lot of data, and the per-gigabyte charge is where NAT bills grow. Pulling model weights of many gigabytes, large container images and datasets through a NAT gateway, every time a node starts, adds up quickly.
AWS's own advice for reducing NAT charges is to use VPC endpoints for AWS services. For models and datasets, keep them in Amazon S3 in the same Region and add a gateway endpoint for S3: traffic goes straight to S3 without passing through NAT, and gateway endpoints have no additional charge. Interface endpoints (for services such as Amazon ECR or Amazon Bedrock) do have their own charges, so compare them with your NAT volume.
Quick recap
- NAT gives private subnets outbound-only internet access.
- NAT gateway: managed, scalable, billed per hour and per gigabyte. NAT instance: cheaper for small setups, but you run it.
- For AI, keep big downloads off NAT: use S3 with a gateway endpoint.