Cloud Infrastructure··2 min read

How We Eliminated $1,400/Month in AWS NAT Gateway Fees Using VPC Gateway Endpoints and Squid Egress Caching

Shafikul Islam

Shafikul Islam

Backend & Cloud Infrastructure Engineer · Infrastructure & Cloud Team Lead

How We Eliminated $1,400/Month in AWS NAT Gateway Fees Using VPC Gateway Endpoints and Squid Egress Caching

The Silent $0.045/GB Tax Inside AWS Private Subnets

If your Kubernetes worker nodes run inside private AWS VPC subnets, outbound traffic routes through an AWS Managed NAT Gateway.

What surprises many engineering teams is the pricing model: in addition to the hourly gateway charge, AWS bills $0.045 per gigabyte processed. When our document-processing and backup workers streamed terabytes of medical PDFs and database snapshots to Amazon S3 in the exact same us-east-1 region, every gigabyte traversed the public NAT Gateway twice.


1. Finding the Top Offenders in VPC Flow Logs

Before changing route tables, we queried VPC Flow Logs to rank the top destination IP blocks by byte volume:

SELECT dstaddr, SUM(bytes) / (1024 * 1024 * 1024) AS total_gb
FROM vpc_flow_logs
WHERE action = 'ACCEPT'
  AND srcaddr LIKE '10.20.%'
GROUP BY dstaddr
ORDER BY total_gb DESC
LIMIT 10;

Over 78% of our NAT Gateway data processing charges came from two sources: regional S3 bucket transfers and repeated Docker image layer downloads during autoscaling events.


2. Provisioning Free S3 and DynamoDB Gateway Endpoints

AWS offers two types of VPC Endpoints: Interface Endpoints (PrivateLink, billed hourly) and Gateway Endpoints for S3 and DynamoDB, which cost $0.00/hour and $0.00/GB.

Attaching a Gateway Endpoint injects a prefix-list route directly into your private subnet route tables:

resource "aws_vpc_endpoint" "s3_gateway" {
  vpc_id            = aws_vpc.production.id
  service_name      = "com.amazonaws.us-east-1.s3"
  vpc_endpoint_type = "Gateway"
  route_table_ids   = aws_route_table.private_subnets[*].id
}

3. Local Registry Mirroring for Autoscaling Nodes

To eliminate the remaining container pull traffic during HPA scale-ups, we enabled K3s embedded registry mirroring (Spegel) and ECR VPC routes so worker nodes share cached OCI layers over the private LAN instead of re-pulling 400MB images through NAT. Monthly NAT Gateway fees dropped by $1,400/month on the very next billing cycle.

Infrastructure & PostgreSQL Advisory

Scaling Infrastructure or Diagnosing P95 Latency?

I help engineering teams diagnose PostgreSQL indexing bottlenecks, concurrency limits, and K3s/Docker deployments. Book a 20-minute call with me to review your setup.

Related Technical Articles