DEV Community

NTCTech
NTCTech

Posted on • Originally published at rack2cloud.com

The $100k AWS Routing Trap: S3 + NAT Gateways (and how to fix it with Terraform)

The $100k AWS Routing Trap: S3 + NAT Gateways

Your "secure by default" AWS architecture is probably bleeding money, and it has nothing to do with over-provisioned EC2 instances.

Sudden increases in cloud spend are rarely caused by compute—they occur because of unintended data transfer paths.

The Trap: "Secure by Default" Routing

Engineers place their compute instances in private subnets with no public IPs. To grant them access to the outside world, they route outbound traffic through a Managed NAT Gateway.

It is secure. It is standard. And it is a financial landmine.

When that private instance needs to pull data from Amazon S3, the setup backfires. Because S3 is a public service endpoint, the traffic from your private subnet is routed out to the Internet Gateway through the NAT Gateway.

The Math: The Double-Metering Penalty

The data leaves the AWS backbone and gets metered twice. If you are downloading 10 TB a day for a data pipeline, it results in a 20 TB billed processing path.

You pay for:

  1. The NAT Gateway’s hourly uptime.
  2. The NAT Gateway processing fee ($0.045/GB).
  3. The standard internet egress fee.

Figure 1: Bypassing the NAT Gateway using a VPC Endpoint collapses the routing path and eliminates internal processing fees.

The Fix: Collapse the Path

Stop treating cloud pipes like traditional LAN cables. You must collapse the routing path by implementing a VPC Gateway Endpoint for S3.

When you do this, your traffic stays inside the internal AWS backbone. The NAT Gateway gets bypassed entirely, and your internal transfer cost drops to $0.00.

Terraform Snippet:

resource "aws_vpc_endpoint" "s3" {
  vpc_id       = aws_vpc.main.id
  service_name = "com.amazonaws.${var.region}.s3"
  vpc_endpoint_type = "Gateway" 
}
Enter fullscreen mode Exit fullscreen mode

The Architecture Rule

Data gravity dictates your baseline cost. Routing dictates your multipliers.


If you are auditing your own multi-region architectures, I've open-sourced the full set of routing mitigation models in our GitHub repository:
👉 cloud-egress-patterns

For the complete architectural deep-dive on Cross-Region VPC peering costs, read the full specification on the Rack2Cloud Control Plane:
👉 The Physics of Data Egress

Top comments (0)