Why your NAT Gateway costs more than your servers

Per-gigabyte processing fees hide in plain sight. How to find them and what to do about them.

  • BITServices team
  • #aws
  • #networking

On AWS a NAT Gateway is billed twice: once for every hour it exists, and once for every gigabyte it processes. In us-east-1 both are $0.045. The hourly part is small. The per-gigabyte part is often not, and it is easy to miss because it shows up as EC2 usage, not as a service of its own.

Where the traffic comes from

Most NAT traffic is traffic that never needed to leave your network:

  • containers pulling images from public registries, or from ECR, on every deploy and every node start
  • services reading and writing S3 or DynamoDB through the NAT instead of a VPC endpoint
  • log and metrics agents shipping data to an external service
  • package installs and updates during builds

Find it

  1. In Cost Explorer, filter on usage type NatGateway-Bytes and group by resource. This shows which NAT Gateways process the most data.
  2. Turn on VPC flow logs for the subnets behind them and group by destination. The top destinations usually explain most of the bill.

Fix it

  • Add gateway endpoints for S3 and DynamoDB. They are free and take S3 and DynamoDB traffic off the NAT completely.
  • Add interface endpoints for ECR and other AWS services you use heavily. They have an hourly and a per-GB cost of their own, so check the numbers, but at high volume they are much cheaper than the NAT.
  • Mirror container images into a registry inside your network, or use a pull-through cache, so nodes stop pulling the same images from the internet.
  • Send logs and metrics in batches and compressed, and drop the debug level in production.
  • Check how many NAT Gateways you run. One per zone is the usual pattern. In development accounts one may be enough.

When it is architecture, not configuration

If the NAT line is still in your top five after these fixes, look at what the services are doing. A service that downloads the same data again and again, or a pipeline that moves large files out to an external service and back, is an architecture problem. Endpoints make it cheaper. Changing the design makes it go away.