AWS cost · Networking
DynamoDB Through a NAT Gateway: The $640 a Month Fix
If your API runs in private subnets and reads from DynamoDB, every response may be passing through a NAT gateway, at $0.045 for each GB it processes. An API reading 14 TB a month pays about $640 for that hop alone. A DynamoDB gateway endpoint carries the same traffic for free, needs no code change, and takes a few minutes to add. Here is how to spot the charge and remove it.
By Jasdeep Bains, SeaGit
·
Key takeaways
- Pods, tasks and instances in private subnets reach DynamoDB's public endpoint through the NAT gateway unless the VPC has a DynamoDB gateway endpoint.
- NAT gateway data processing is $0.045 per GB in us-east-1, on top of the hourly charge. 14.3 TB a month of DynamoDB reads costs about $644.
- Gateway endpoints exist only for DynamoDB and S3, and they cost nothing. They add a route to your route tables; the SDK keeps using the same endpoint name.
- Look for NatGateway-Bytes in Cost Explorer and compare it with your DynamoDB read volume.
- A gateway endpoint only covers tables in the same Region as the VPC.
Why DynamoDB traffic goes through NAT
DynamoDB is reached at a public regional endpoint such as dynamodb.us-east-1.amazonaws.com. A workload in a private subnet has no route to the internet except the default route to a NAT gateway. So unless something says otherwise, every DynamoDB request and response passes through that NAT gateway, and AWS bills each gigabyte it processes.
A gateway endpoint says otherwise. It adds a route for DynamoDB's prefix list to the subnet route tables, pointing at the endpoint instead of the NAT gateway. Traffic stays on the AWS network and the NAT processing charge disappears.
What the NAT hop costs
| DynamoDB traffic a month | Through NAT | Through a gateway endpoint |
|---|---|---|
| 100 GB | $4.50 | $0 |
| 1 TB | about $46 | $0 |
| 10 TB | about $461 | $0 |
| 14.3 TB (100 million 5 KB reads a day) | about $644 | $0 |
The hourly NAT charge stays, since other traffic still needs the NAT gateway. Only the per-GB processing for DynamoDB goes away. The Vercel vs AWS cost calculator shows this line for your own traffic: switch the gateway endpoint off and the NAT charge appears.
Check whether you are paying it
- Cost Explorer: group by usage type and look for
NatGateway-Bytes(prefixed by the Region code, such asUSE1-NatGateway-Bytes). Large values with modest internet traffic point at AWS service traffic going through NAT. - Route tables: a private route table with a DynamoDB endpoint has a route whose destination is a prefix list (
pl-…) and whose target is avpce-…endpoint. No such route means DynamoDB traffic goes through NAT. - CloudWatch: the NAT gateway's
BytesOutToDestinationmetric should drop as soon as the endpoint is added.
Add the gateway endpoint
With the AWS CLI, attach the endpoint to every private route table in the VPC:
aws ec2 create-vpc-endpoint \
--vpc-id vpc-0abc123 \
--vpc-endpoint-type Gateway \
--service-name com.amazonaws.us-east-1.dynamodb \
--route-table-ids rtb-0private1 rtb-0private2Or in Terraform:
resource "aws_vpc_endpoint" "dynamodb" {
vpc_id = aws_vpc.main.id
service_name = "com.amazonaws.us-east-1.dynamodb"
vpc_endpoint_type = "Gateway"
route_table_ids = aws_route_table.private[*].id
}Add the S3 gateway endpoint the same way. It is also free and carries container image layers from ECR, which are stored in S3. No application change is needed: the SDK resolves the same endpoint name, and the route table sends the traffic to the endpoint. An endpoint policy can limit which tables are reachable through it.
Limits to know
- Same Region only. A gateway endpoint covers DynamoDB in the VPC's own Region. Tables in another Region are still reached through NAT, and cross-Region transfer charges apply.
- Only inside the VPC. On-premises networks and peered VPCs cannot use another VPC's gateway endpoint. DynamoDB also offers paid interface endpoints for those cases.
- Only DynamoDB and S3. Other AWS services need interface endpoints, which are charged by the hour and by the GB.
On SeaGit, the DynamoDB and S3 gateway endpoints are checkboxes on the network form, so new clusters start without the NAT charge.