Sphere
Log in Join

Our AWS bill jumped $2,400 from NAT Gateway data processing charges

Finance forwarded the AWS invoice on a Monday with one word in the subject: "why". The bill was about $2,400 higher than the month before. Nothing in our deployment had changed, no new instances, no traffic spike that anyone could see. The culprit was a service line most people ignore until it hurts.

## What the bill actually said

In Cost Explorer, grouped by usage type, the difference was almost entirely one line:

NAT Gateway - DataProcessing (USD)     47,912 GB   $2,156.04
NAT Gateway - DataProcessing (USD) (prior) $118.72

At $0.045 per GB in us-east-1, roughly 48TB had crossed a NAT gateway. We have three NAT gateways in three AZs, so per-gateway numbers looked normal in isolation. It was the total that was absurd.

## Where the traffic came from

Every private subnet had a route like this:

0.0.0.0/0   nat-0b41f2c9d81e7a330

That is fine for the internet. The problem is that it also catches S3. We had a nightly job that copied about 1.2TB of Parquet files between two buckets, plus a dozen pods pulling layers from ECR on every deploy. Because there was no S3 gateway endpoint in the route table, all of that traffic went to the NAT gateway's public IP, got billed as data processing, and then came back into S3 through the private network path.

There was also a smaller mistake: apt and pip installs in CI ran on every build, and the build subnet was private. Add those up over thirty days and it is real money.

## Finding it with flow logs

VPC Flow Logs were already on, which saved me. I ran an Athena query against the published logs to see where the bytes went:

SELECT dstaddr, sum(bytes)/1e12 AS tb
FROM vpc_flow_logs
WHERE day = '2024/03/18'
AND srcaddr LIKE '10.42.%'
GROUP BY dstaddr
ORDER BY tb DESC
LIMIT 10;

The top destination was an S3 prefix-list IP range in the same region, at about 40TB for that one day alone. That was the confirmation. I also hit this while trying to add the endpoint in the wrong region:

$ aws ec2 create-vpc-endpoint --vpc-id vpc-0abc123def456789 \
--service-name com.amazonaws.us-east-1.s3 \
--route-table-ids rtb-0fedcba9876543210

An error occurred (InvalidServiceName) when calling the CreateVpcEndpoint operation:
The VPC endpoint service com.amazonaws.us-east-1.s3 does not exist

Turns out my AWS_DEFAULT_REGION was set to eu-west-1 from another profile. S3 gateway endpoint names are regional, so that one was on me.

## The fix

Gateway endpoints are free and add a route entry that beats the default route:

aws ec2 create-vpc-endpoint \
--vpc-id vpc-0abc123def456789 \
--service-name com.amazonaws.us-east-1.s3 \
--route-table-ids rtb-0fedcba9876543210 rtb-0aaa111bbb222ccc

aws ec2 create-vpc-endpoint \
--vpc-id vpc-0abc123def456789 \
--service-name com.amazonaws.us-east-1.ecr.api \
--route-table-ids rtb-0fedcba9876543210

Afterwards the route tables showed pl-6fa54006 -> vpce-0abc... for the S3 prefix list. The next bill dropped back to about $180 for NAT processing. Same workload, same buckets.

## The part I still do not love

Gateway endpoints only work for S3 and DynamoDB in the same region. Our analytics job reads a bucket in eu-west-1, and that traffic still crosses a NAT gateway or a peering connection. Replicating the bucket is the obvious answer, but that costs its own money and we have not finished the math yet. For now I set a billing alarm at $300 a month on the NAT line so this cannot sneak up on us again.