How it works
The explanation, with examples you can run.
Data transfer
| Traffic | Billed? |
|---|---|
| From the internet into AWS | No |
| From AWS out to the internet | Yes, per GB (a monthly free allowance applies) |
| Between Availability Zones in a Region | Yes, per GB in each direction |
| Between Regions | Yes, per GB |
| Within one zone over private IPs | Generally no |
| To S3 or DynamoDB through a gateway endpoint | No endpoint charge |
Consequences: a multi-zone design pays for its replication and cross-zone calls (usually worth it, but measure it); serving large downloads straight from S3 or EC2 to the internet costs more than through CloudFront in many cases; and moving data between Regions for analytics can cost more than the analytics.
NAT gateways
A NAT gateway is billed for each hour it exists and each gigabyte it processes, and the traffic then pays normal transfer too. Typical offenders: pulling container images, calling S3 or DynamoDB without endpoints, and sending logs or metrics to AWS APIs from private subnets. Fixes are gateway endpoints for S3 and DynamoDB (free), interface endpoints for heavily used services, image caching, and checking the NAT gateway's BytesOutToDestination metric to see who is talking.
Things that bill while idle
- Public IPv4 addresses: AWS charges per hour for every public IPv4 address, whether attached to an instance, a load balancer, a NAT gateway or sitting unused as an Elastic IP.
- EBS volumes and snapshots left behind after instances are terminated, and snapshots kept forever.
- Load balancers, NAT gateways and interface endpoints in environments nobody uses.
- Over-provisioned capacity: instances at 5 % CPU, provisioned DynamoDB tables or RDS instances sized for a launch that never came.
- CloudWatch Logs with no retention, and high-cardinality custom metrics.
- S3 incomplete multipart uploads and old object versions without lifecycle rules.
Making cost an engineering signal
- Tag everything with owner, service and environment, and activate those tags as cost allocation tags.
- Create AWS Budgets with alerts at, say, 80 % and 100 % of the expected monthly spend, per account or per tag. Turn on Cost Anomaly Detection.
- Read Cost Explorer grouped by usage type:
DataTransfer-Regional-Bytes,NatGateway-BytesandPublicIPv4lines tell you more than "EC2-Other". - Commit to steady baselines with Savings Plans, use Spot for interruptible work, and pick Graviton (Arm) instances where your software supports it.
- Delete what is idle, and give test environments a schedule or an expiry date. Infrastructure as code makes that safe: what was created by a pipeline can be destroyed by one.
Check yourself
3 questions. Get them all right to finish this topic.
0 of 3 right so far. Get all three to finish this topic.