AWS Builder Center

I Stopped Routing My S3 Traffic Through a NAT Gateway: What VPC Endpoints Taught Me

A Lambda bill showed NAT data-processing charges outweighing Lambda and S3 combined. VPC endpoints keep that traffic on the AWS network — cheaper and simpler for S3 and DynamoDB, and worth weighing carefully for other services.

yub 😎
For a long time, my mental model of a VPC was simple: private subnets need a NAT gateway to reach anything outside them, and that is just the price of doing things properly. It worked. It also quietly billed me for traffic that never needed to leave AWS at all.
The moment that clicked for me was not dramatic. I was looking at a bill for a small side project — a Lambda function in a private subnet that read files from S3 and wrote results back — and the NAT data-processing charges were bigger than the Lambda and S3 charges combined. Nothing was broken. Nothing was slow. I was just paying a toll on every single request to a service that lived in the same cloud, in the same region, behind the same provider's network.
That is the core idea behind VPC endpoints, and it is worth understanding even if you never touch a production VPC: some AWS traffic does not need to go out to the internet at all.
What actually changed: A VPC endpoint lets resources inside your VPC connect to a supported AWS service privately, without going through the internet, a NAT gateway, or a VPN. For S3 and DynamoDB, this is a gateway endpoint: you add a route to your subnet's route table pointing at the endpoint, and traffic to those services stays on the AWS network. For most other services — SQS, Secrets Manager, ECR, CloudWatch Logs, and many more — it is an interface endpoint, powered by PrivateLink, which puts an elastic network interface with a private IP inside your subnet.
In my case, the fix was almost boring. I added a gateway endpoint for S3 to the private subnets, updated the route tables, and the Lambda's S3 calls stopped flowing through the NAT gateway. The function did not get faster in any way I could measure — S3 was never the bottleneck — but the NAT bill dropped, and the architecture got simpler to reason about: traffic to S3 no longer depended on a NAT gateway being up, correctly sized, and paid for by the gigabyte.
The trade-offs nobody mentions first: Gateway endpoints are free, which makes them an easy yes for S3 and DynamoDB. Interface endpoints are not: you pay per hour for each endpoint, plus data-processing charges. That flips the calculation. One interface endpoint for a service you call rarely can cost more than the NAT traffic it replaces. I learned to check this before adding endpoints everywhere, not after.
There is also a subtlety that caught me out the first time: endpoint policies. A gateway endpoint for S3, by default, allows access to all S3 buckets. If you want to restrict it to your own buckets, you write an endpoint policy — and if you get that policy wrong, your application fails with an access error that looks, at first glance, like an IAM problem. It is not. The IAM role was fine; the endpoint policy was the gate. Now I treat endpoint policies as part of the same review as IAM policies, not as an afterthought.
Security groups matter for interface endpoints too. The endpoint's network interface needs a security group that allows traffic from your resources on the right port, usually 443. Forget that rule and you get timeouts, not permission errors — which makes debugging feel much harder than it should be.
What I do now: My rule of thumb is simple. For S3 and DynamoDB, gateway endpoints go in by default whenever I have private subnets — they are free, and there is rarely a reason not to. For interface endpoints, I add them deliberately, one service at a time, when one of two things is true: the service is called often enough that NAT data-processing charges would exceed the endpoint's hourly cost, or the traffic is sensitive enough that I want it to never touch the public internet, regardless of cost.
That second reason matters more than I first thought. Keeping traffic private is not just about the bill. It removes a whole class of "what if the NAT gateway goes down or the route table is wrong" failures from the path between my application and the services it depends on. Fewer moving parts in the critical path is a reliability win, not just a cost win.
The takeaway is not "use VPC endpoints everywhere." It is to ask, for each private workload, a question I skipped for too long: does this traffic actually need to leave AWS? If the answer is no, there is probably a private path already waiting, and it may be cheaper and simpler than the internet route I set up by default.
What is the first service you would move off your NAT gateway — and did the bill, or the security argument, convince you first?
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article