You spot it in the bill audit. The NatGateway-Bytes line is creeping toward 8% of the AWS bill, which is more than the EC2 fleet running the application. The instances behind the NAT are mostly pulling files from S3, writing CloudWatch logs, and hitting the AWS APIs from a few cron jobs. None of that has to leave the VPC. The fix is interface and gateway VPC endpoints — but only some of them, only for the right services, and only after the math says it pays back inside a quarter.
What’s happening
A NAT gateway has two charges that compound: an hourly charge per AZ where the NAT is deployed, and a per-gigabyte data-processing charge on every byte that flows through. The hourly is the floor; the per-gigabyte is what makes the line item move.
When an EC2 instance in a private subnet talks to an AWS service via the public endpoint (s3.<region>.amazonaws.com, dynamodb.<region>.amazonaws.com, logs.<region>.amazonaws.com, and the rest), the traffic goes out through the NAT and incurs the per-gigabyte charge — even though both endpoints are inside AWS. A VPC endpoint provides a private route from the subnet directly to the AWS service, skipping the NAT entirely.
There are two flavors:
- Gateway endpoints are free to operate. They exist for S3 and DynamoDB only. There is no reason not to deploy them in every VPC.
- Interface endpoints are powered by PrivateLink. They support most other AWS services. They charge an hourly per-endpoint per-AZ plus a per-gigabyte fee that is smaller than the NAT per-gigabyte fee. They pay back above a service-specific traffic threshold.
The math: if g is the gigabytes per month going to a service through the NAT, and the NAT per-GB fee is n while the interface-endpoint per-GB fee is i, then the interface endpoint pays back when g × (n − i) exceeds the monthly hourly cost of the endpoint. The hourly cost is roughly equivalent to a few gigabytes of NAT processing, so the break-even is in the low tens of gigabytes for most regions. Below that, leave it on the NAT; above that, the endpoint wins.
For gateway endpoints (S3, DynamoDB), there is no per-GB charge and no hourly. The break-even is zero — deploy them unconditionally.
How to verify
Step 1 — find out what is flowing through the NAT and where it is going.
VPC Flow Logs is the source of truth. Enable on the VPC if not already; route to CloudWatch Logs or S3. The schema captures srcaddr, dstaddr, bytes, and action. For finding NAT-bound traffic, filter dstaddr against the public CIDRs of the relevant AWS services.
aws logs start-query \
--log-group-name /vpc/flowlogs \
--start-time $(date -v-7d +%s) \
--end-time $(date +%s) \
--query-string 'fields @timestamp, srcaddr, dstaddr, bytes
| filter action = "ACCEPT"
| stats sum(bytes) as total_bytes by dstaddr
| sort total_bytes desc
| limit 50'
Reverse-DNS the top destinations. The ones in the form s3-r-w.<region>.amazonaws.com, dynamodb.<region>.amazonaws.com, logs.<region>.amazonaws.com, ec2.<region>.amazonaws.com, ssm.<region>.amazonaws.com, sts.<region>.amazonaws.com, secretsmanager.<region>.amazonaws.com, kms.<region>.amazonaws.com are all candidates for VPC endpoints.
Step 2 — cross-reference with the Cost & Usage Report to confirm the dollar weight of each destination.
The CUR has a lineItem/UsageType of NatGateway-Bytes and a lineItem/ResourceId of the NAT itself. The destination breakdown is not in the CUR — that is what the Flow Logs query above is for. Combine them: gigabytes per destination from Flow Logs × cost per gigabyte from the CUR = monthly cost contribution of that destination.
Step 3 — rank by potential savings.
S3 — gateway endpoint, free, savings = 100% of S3 NAT traffic
DynamoDB — gateway endpoint, free, savings = 100% of DynamoDB NAT traffic
CloudWatch Logs — interface endpoint, savings = NAT GB cost − endpoint GB cost − hourly
ECR (Docker pulls) — interface endpoint, often a big win
SSM / Secrets / KMS — interface endpoint, low traffic but cheap to deploy
The order matters because the gateway endpoints are unconditional wins and should ship first.
The fix
Deploy gateway endpoints for S3 and DynamoDB in every VPC, before touching anything else. The Terraform stanza is short and idempotent:
resource "aws_vpc_endpoint" "s3" {
vpc_id = aws_vpc.this.id
service_name = "com.amazonaws.${var.region}.s3"
vpc_endpoint_type = "Gateway"
route_table_ids = aws_route_table.private[*].id
}
resource "aws_vpc_endpoint" "dynamodb" {
vpc_id = aws_vpc.this.id
service_name = "com.amazonaws.${var.region}.dynamodb"
vpc_endpoint_type = "Gateway"
route_table_ids = aws_route_table.private[*].id
}
Once those are in place, re-run the Flow Logs query against the next 24 hours. The NAT bytes line should drop measurably. If it does not, the application is not using the AWS SDK default endpoint resolution — check for hardcoded URLs or proxies in code or environment variables.
For interface endpoints, compute the break-even per service. The break-even traffic for an interface endpoint is roughly the monthly hourly cost divided by the gap between the NAT per-GB and the endpoint per-GB. Anything above the threshold gets an endpoint; anything below stays on the NAT. Deploy in only the AZs where workload runs — a three-AZ deployment is three times the hourly cost.
resource "aws_vpc_endpoint" "logs" {
vpc_id = aws_vpc.this.id
service_name = "com.amazonaws.${var.region}.logs"
vpc_endpoint_type = "Interface"
subnet_ids = aws_subnet.private_app[*].id # one per AZ in use
security_group_ids = [aws_security_group.endpoints.id]
private_dns_enabled = true
}
private_dns_enabled = true is the load-bearing line — it makes the AWS SDK pick up the endpoint automatically without code changes. Without it, you have to override the endpoint URL in every client. Set it.
One trap to avoid: interface endpoints have a hourly charge per AZ, so a small workload in a single AZ may not justify even a single endpoint. The math applies; do not deploy by reflex.
Re-run the bill audit at the end of the next billing cycle. The NAT line should now consist of legitimate egress to the public internet (third-party APIs, npm, package mirrors, etc.) and nothing else. That is the right shape.
Stack Harbor handles VPC topology and egress-cost optimization as part of Cloud Compute operations. If your NAT line is doing too much work, start with a network audit.