Sub topic 12
Reducing data transfer costs
Data transfer charges are easy to miss because no single resource owns them. They show up as line items on EC2, S3, NAT gateways and load balancers. This chapter assumes you know how to read a bill in Cost Explorer, and that you know what a VPC, an Availability Zone (AZ) and a NAT gateway are. It uses AWS prices and names. Other providers have similar rules with different rates.
How data transfer is billed
Providers charge by direction and by distance. Traffic coming into the cloud is usually free. Traffic leaving it, or crossing a boundary inside it, costs money. The boundaries are:
- Between the provider and the internet.
- Between regions.
- Between AZs in one region.
- Through managed network services such as NAT gateways.
The rates below are approximate US figures. Check the current pricing pages before you build a business case on them.
| Path | Approximate charge | Typical cause |
|---|---|---|
| Internet to AWS (in) | Free | Uploads, API requests |
| AWS to internet (out) | About $0.09 per GB, after a small free monthly allowance | Serving files, API responses |
| Region to region | About $0.02 per GB | Replication, cross-region calls |
| AZ to AZ in a region | About $0.01 per GB in each direction | Multi-AZ databases, chatty microservices |
| Through a NAT gateway | About $0.045 per GB processed, plus an hourly fee | Private subnets reaching S3, ECR or the internet |
| Same AZ, private IP | Free | Well-placed traffic |
Two details cause most surprises. Cross-AZ traffic is billed on both the sending and the receiving side, so a 1 GB transfer costs about $0.02 in total. A NAT gateway adds its per-GB processing fee on top of any transfer charge that applies after it.
Step 1: Measure before changing anything
Start by finding which transfer paths cost the most. Group the spend by usage type and keep only transfer-related and NAT usage. Save this filter as dt-filter.json:
{
"Dimensions": {
"Key": "USAGE_TYPE",
"Values": ["DataTransfer", "NatGateway"],
"MatchOptions": ["CONTAINS"]
}
}Then run the query:
aws ce get-cost-and-usage \
--time-period Start=2026-10-01,End=2026-11-01 \
--granularity MONTHLY \
--metrics UnblendedCost UsageQuantity \
--group-by Type=DIMENSION,Key=USAGE_TYPE \
--filter file://dt-filter.jsonUsage type names carry a region prefix and a path hint. Typical examples are:
USE1-DataTransfer-Out-Bytes: traffic to the internet.USE1-DataTransfer-Regional-Bytes: traffic between AZs in the region.USE1-USW2-AWS-Out-Bytes: traffic between regions.USE1-NatGateway-Bytes: data processed by a NAT gateway.
The query tells you which path is expensive but not which workload causes it. To find the workload, turn on VPC Flow Logs for the suspect subnets. Query them with Athena or CloudWatch Logs Insights, and sum bytes by source and destination address. The tag-based allocation from the earlier chapter helps here, because you can then map those addresses to an owner.
Step 2: Fix the pattern
Most savings come from five patterns. Work through them in the order your measurements justify, not in the order listed.
Bypass the NAT gateway for AWS services
A common cause of high bills is a private subnet that reads from S3 through a NAT gateway. Every byte then pays the NAT processing fee. A gateway endpoint for S3 or DynamoDB routes that traffic privately inside AWS. It has no hourly or per-GB charge.
aws ec2 create-vpc-endpoint \
--vpc-id vpc-0123456789abcdef0 \
--service-name com.amazonaws.us-east-1.s3 \
--vpc-endpoint-type Gateway \
--route-table-ids rtb-0123456789abcdef0Replace the VPC ID, route table ID and region with your own. The endpoint adds a route to the route table, so the change takes effect without touching application code. Gateway endpoints exist only for S3 and DynamoDB. Other services, such as ECR, CloudWatch or Secrets Manager, need interface endpoints. Those cost an hourly fee per AZ plus a per-GB fee, which is lower than NAT processing. An interface endpoint pays off only when the traffic is large enough to cover the hourly fee. Container image pulls from ECR are a frequent case where it does.
Use a CDN for internet egress
A content delivery network (CDN) such as CloudFront caches responses at edge locations. This helps in two ways:
- Cache hits never reach your origin, so you pay less origin egress.
- Transfer from AWS origins such as S3 or an ALB to CloudFront is free. CloudFront's own per-GB rate to the internet is usually lower than direct EC2 or S3 egress, and it falls with volume.
The cache hit ratio decides how much you save. Raise it with long Cache-Control max-age values on static assets, versioned file names so you can cache for a long time, and a small set of cache key parameters. Forwarding every query string and header creates many cache variants and cuts the hit ratio.
Reduce the bytes themselves too. Enable gzip or Brotli compression for text content, serve modern image formats, and paginate or filter API responses instead of returning whole objects.
Keep traffic inside an AZ where it is safe
Cross-AZ traffic is a design cost. You pay it for high availability, so do not remove it blindly. Look for the avoidable cases:
- A service calls a dependency that may sit in any AZ. Prefer same-AZ endpoints when the dependency is healthy, for example with zone-aware routing in your service mesh or load balancer.
- Kubernetes pods spread across AZs call each other constantly. Topology-aware routing can keep traffic local.
- A database read replica sits in a different AZ from the readers. Place readers and replicas together, and keep at least one replica elsewhere for failover.
- Application Load Balancers with cross-zone load balancing send traffic across AZs, but that traffic is not charged for ALB. For a Network Load Balancer, cross-zone traffic is charged as regular cross-AZ transfer.
Weigh each change against availability. If keeping traffic local means one AZ gets overloaded or the failover path is untested, the saving is not worth it.
Reduce cross-region movement
Region-to-region transfer comes from replication, backups, analytics jobs that read remote data, and services that call each other across regions. Options include:
- Run compute in the same region as the data, instead of pulling large datasets across.
- Replicate only the buckets and prefixes that need disaster recovery or low-latency reads. S3 replication rules accept prefix and tag filters.
- Compress and batch data before it crosses a region boundary.
- Check whether cross-region backup copies are required, and how long you retain them.
Watch for hidden internet paths
Some traffic leaves AWS without anyone intending it. Examples are public IPv4 addresses used between your own services, which route out and back, and tools that download from public S3 URLs instead of using in-region access. Use private addressing and in-region endpoints for service-to-service calls. Note that AWS also charges an hourly fee for each public IPv4 address, so removing unnecessary ones saves money directly.
Common mistakes
- Optimizing the wrong path. Teams often tune egress while NAT processing is the larger item. Measure first.
- Creating an endpoint but not updating routing. A gateway endpoint only works for subnets whose route tables include it. Check that each private subnet's route table is associated.
- Forgetting that the fix has a cost. Interface endpoints, CloudFront requests and extra replicas have their own charges. Estimate the break-even volume.
- Judging by one month. Transfer varies with traffic, releases and batch jobs. Compare the same usage type across several months and divide by a business measure such as requests, which links back to unit costs.
- Breaking resilience. Removing cross-AZ paths can turn a cost saving into an outage risk.
Checking the result
After a change, re-run the Step 1 query for the following period and compare the matching usage type. A successful NAT fix shows NatGateway-Bytes falling while the S3 request volume stays flat. A CDN change shows DataTransfer-Out-Bytes from the origin falling while CloudFront usage rises by a smaller amount. If total cost does not fall, check that the traffic actually uses the new path, using flow logs.
Exercise
A private subnet runs batch jobs that read about 20 TB per month from S3 through a NAT gateway at roughly $0.045 per GB processed. What change cuts most of that cost, and approximately how much does it save per month?
Show answer
Add an S3 gateway endpoint and associate it with the subnet's route table. Gateway endpoints have no hourly or per-GB charge, so the NAT processing fee for that traffic disappears. 20 TB is about 20,000 GB, so the saving is roughly 20,000 x $0.045 = $900 per month. Using 1,024 GB per TB gives about $920. Confirm by checking that NatGateway-Bytes drops in the next billing period.
Exercise
Why can moving a chatty service pair into a single AZ save money, and what risk does it add?
Show answer
Traffic between AZs is billed at about $0.01 per GB in each direction, while traffic inside one AZ over private IPs is free. Keeping the pair together removes that charge. The risk is lower availability: if that AZ fails, both services fail together, so you need a tested failover path in another AZ.