Task 4.4 · 22 min read
Network Cost
Services in this lesson
- Amazon VPCin scope
- NAT gatewayscope not listed
- Amazon EC2in scope
- AWS Transit Gatewayin scope
- AWS Direct Connectin scope
- AWS Site-to-Site VPNin scope
- Amazon CloudFrontin scope
- AWS Global Acceleratorin scope
- Elastic IP addressesscope not listed
- AWS Cost and Usage Reportin scope
What the exam tests
- Whether you know which traffic is free and which is billed, by direction. Data into AWS from the internet is free, and data out to the internet is billed per GB. Traffic over private IP addresses inside one Availability Zone (AZ) is free. An AZ is one or more isolated data centers inside a Region, a geographic area with several AZs.
- Whether you spot the hidden cost of a NAT gateway. It bills an hourly charge per gateway (per AZ for a regional gateway), plus a per-GB processing charge on every byte that passes through it. Internet-bound traffic also pays normal data transfer out, and the gateway's Elastic IP bills as a public IPv4 address.
- Whether you choose a gateway endpoint first for private access to AWS services. Gateway endpoints exist only for Amazon S3 and Amazon DynamoDB and have no charge, so they beat interface endpoints and any NAT path.
- Whether you keep chatty traffic in one Availability Zone. You should also know why one NAT gateway per Availability Zone can cut cross-AZ charges.
- Whether you pick the cheaper path for the volume. CloudFront or Direct Connect fit large outbound volume, and Site-to-Site VPN fits low-volume hybrid links. A transit gateway is a central hub that VPCs and on-premises links attach to. It fits only when the number of networks justifies its hourly and per-GB charges.
This lesson owns the charges. How the network is built (virtual private cloud, or VPC, layout, route tables, security groups, VPN and Direct Connect encryption) is in task 1.2, secure workloads and applications.
Throughput, MTU (maximum transmission unit), peering scale and per-tunnel VPN throughput are in task 3.4, network performance. So are Global Accelerator for latency and the mechanics of transit gateways and endpoints. That includes why a gateway endpoint can't be reached from on-premises or through a transit gateway.
CloudFront mechanics are in task 2.1c. S3 storage cost is in task 4.1. Throttling strategy is not taught here.
The core concept
Network cost is a meter on every gigabyte, and the rate depends on where the bytes start and where they end. So a network cost question is a question about the path: which hops does the traffic cross, and which of them charge?
An analogy: toll roads around a city
Picture a city with toll roads. Driving inside your own neighborhood is free. Crossing to another district costs a small toll each way, driving to another city costs more, and leaving the country costs the most.
Coming into the city from abroad is free. Some roads have a booth that charges for every car that passes, and the booth also charges rent by the hour. A private service road straight to the city warehouse is free for residents.
Where the analogy breaks: road tolls charge per car, but AWS charges per gigabyte moved.
Walk the traffic through it
The diagram is the decision you make for each kind of traffic. Pick the destination first, then the volume.
Kestrel Maps renders map tiles on instances in private subnets across two Availability Zones. A private subnet has no direct route to the internet. Adaeze is the cloud architect, and Tomas reads the Cost and Usage Report (CUR), the detailed AWS billing file.
- Tomas spots the NAT line. A NAT gateway (network address translation) lets private instances reach the internet. It bills an hourly charge per gateway (per AZ for a regional gateway), plus a per-GB processing charge on every byte that passes through it. Internet-bound traffic also pays normal data transfer out, and the gateway's Elastic IP bills as a public IPv4 address.
- Tile jobs read imagery from S3 in the same Region. That is the first diamond in the diagram. Adaeze adds a gateway endpoint for S3, a route-table entry that sends S3 traffic straight to the service.
- The S3 bytes leave the NAT bill. The gateway endpoint has no hourly charge and no per-GB charge. Before, Kestrel Maps paid NAT processing for traffic that never needed to leave the VPC.
- The renderers fetch secrets from AWS Secrets Manager. That is the second diamond. An interface endpoint (AWS PrivateLink) is a private network interface for one service, billed per hour in each AZ plus per GB.
- Adaeze checks the volume first. The secrets traffic is light, so she keeps it on NAT for now. The endpoints deep dive below explains when an interface endpoint pays off.
- The renderers download software packages. That is low-volume internet egress (outbound traffic), so it goes to a NAT gateway. Adaeze finds one gateway in AZ A serving both zones.
- AZ B pays cross-AZ charges. Its traffic crosses to AZ A, and traffic between AZs is billed in both directions for most services. Adaeze adds a NAT gateway in AZ B and points that zone's route at it.
- Millions of users download tiles. That is high-volume internet egress. Adaeze puts Amazon CloudFront, the AWS content delivery network, in front of S3, because transfer from an AWS origin to CloudFront is not charged.
- A nightly export goes to the office data center. It is steady and large, so Adaeze uses AWS Direct Connect, a dedicated private link. Its data out is billed at the Direct Connect rate, not the internet rate. A Site-to-Site VPN would suit a smaller link (see below).
- A partner team gets its own VPC. That is the diagram's third branch. Two VPCs need only VPC peering, a direct link with no hourly charge, while many VPCs and on-premises links justify a transit gateway.
- Tomas checks the next bill. The S3 path costs nothing and AZ B no longer pays cross-AZ charges. The internet egress line has shrunk to CloudFront's per-GB rate.
The rules the exam tests
- Direction: data into AWS from the internet is free. Data out to the internet is billed per GB.
- Distance: traffic over private IP addresses inside one AZ is free. Same-AZ traffic over public or Elastic IP addresses (static public IPv4 addresses you keep) is charged.
- Further costs more: between AZs costs a little, between Regions more, and to the internet the most.
- Between AZs: billed in both directions for most services. The CUR shows an inbound and an outbound line for each resource.
- Between Regions: billed on the outbound side, from the source Region only. The destination side has no charge.
- Two kinds of charge: per GB for data moved or processed, and hourly for a resource that exists whether or not traffic flows. The deep dive below lists which is which.
- Gateway endpoints exist only for S3 and DynamoDB, and they are free. Check them before any other path.
Deep diveWhich resources charge per GB and which per hour
Data moved is billed per GB between AZs, between Regions and out to the internet. Data processed is billed per GB by NAT gateways, interface endpoints and transit gateways.
Hourly charges apply to NAT gateways, interface endpoints, transit gateway attachments, VPN connections, Direct Connect ports and public IPv4 addresses.
Deep diveZonal and regional NAT gateways
A zonal NAT gateway lives in one Availability Zone. A workload in AZ A that uses a gateway in AZ B also pays cross-AZ charges on that traffic.
The zonal fix is one NAT gateway per AZ that has workloads. Each subnet's route points at the gateway in its own zone, and that is the design the lab builds.
One gateway per AZ also gives you high availability, but it multiplies the hourly charge.
A regional NAT gateway is not tied to one zone. In automatic mode it expands into each AZ that has workloads, so you don't add a gateway per zone.
A regional NAT gateway is billed for each hour it is configured in each AZ, plus a per-GB processing charge. Check the NAT gateway pricing page for the current rate.
Deep diveGateway endpoints versus interface endpoints
Steps 2 and 3 showed the free gateway endpoint for S3 and DynamoDB. See the S3 gateway endpoint page for the route it adds.
An interface endpoint covers many more services. It charges per hour for each endpoint in each AZ, plus per GB. So it is cheaper than NAT only when the traffic is heavy.
Deep diveNAT instances and public IPv4 addresses
A NAT instance is an EC2 instance you run yourself as the NAT device. You pay the instance cost and the normal data transfer charges, with no NAT processing fee.
You also own patching, sizing, scaling and failover. For a small lab or a dev VPC with little traffic it can be cheaper.
For production it is usually the wrong trade. Exam stems that say "least operational overhead" point to a managed NAT gateway.
AWS charges an hourly rate for every public IPv4 address. That covers an address on a running instance, an Elastic IP address or a load balancer, whether in use or idle.
Check the VPC pricing page for the current rate. Public instances that could sit behind a load balancer or a NAT gateway can cut that line item. So can a move to IPv6 where the application allows it.
Paying for volume, links and DNS
Steps 8 and 9 moved high-volume traffic off the internet. These are the cost rules for each link and hub the walkthrough could have picked, plus DNS.
- CloudFront bills per GB for data out to viewers. Data transfer from an AWS origin to CloudFront is waived (see the CloudFront pricing page).
- Direct Connect charges a port-hour fee that depends on capacity. Choose the smallest dedicated port (1, 10, 100 or 400 Gbps) or hosted connection that covers the sustained peak. A hosted connection is one provisioned for you by an AWS Direct Connect Partner.
- Direct Connect data out is billed at a per-GB rate that varies by Region and location (see the Direct Connect pricing page).
- Site-to-Site VPN is an encrypted tunnel over the internet, billed per connection-hour. Standard AWS data transfer charges apply to the data sent over it.
Deep diveVPN tunnels and capacity
Each Site-to-Site VPN connection has two tunnels. Using both gives redundancy without a second connection charge. A second connection does add charges.
Each tunnel carries up to 1.25 Gbps by default, so a VPN suits low volume. See the VPN pricing page and task 3.4.
Deep diveGlobal Accelerator is a performance purchase
AWS Global Accelerator bills an hourly rate for each accelerator, plus data transfer. That includes an incremental data transfer charge on top of standard rates (see the Global Accelerator pricing page).
Choose it when the requirement is latency, static entry IP addresses or failover across Regions. Don't choose it to lower the bill.
Deep divePeering versus a transit gateway
VPC peering links two VPCs directly and has no hourly charge. You pay only the data transfer rate for the path.
A transit gateway is a central hub that VPCs and on-premises links attach to. It charges an hourly rate per VPC attachment and a per-GB rate for data it processes.
Data sent from a peering attachment to a transit gateway has no processing charge (see the transit gateway pricing page).
A transit gateway removes the need for a full mesh of peering connections as the number of VPCs grows. For two or three VPCs, peering is cheaper.
For a hub with many VPCs and on-premises links, the transit gateway often costs less to operate. Watch its per-GB charge.
Deep diveDNS: alias queries are free
You pay for each Route 53 hosted zone and for the standard DNS queries it answers. An alias record is a Route 53 record that points at an AWS resource.
Alias queries to a load balancer, CloudFront distribution, Global Accelerator accelerator or S3 static website have no query charge. So use alias records for those targets.
For details, see alias and CNAME records and the Route 53 pricing page.
Decision guide
| If the question says… | Reach for… | Because… |
|---|---|---|
| private subnet instances read or write S3 or DynamoDB in the same Region; MOST cost-effective | Gateway endpoint for S3 or DynamoDB | No hourly or processing charge, and that traffic stops using the NAT gateway |
| private workload calls another AWS service (for example, Systems Manager or Secrets Manager) heavily | Interface endpoint in each AZ that has workloads | Replaces NAT processing, but bills per hour per AZ plus per GB; model volume |
| private instances in several AZs need internet egress, low volume, LEAST operational overhead, no private connectivity | Regional NAT gateway | Expands into each AZ with workloads, no per-zone gateways; still hourly and per GB |
| private instances in several AZs need zonal NAT gateways that keep each zone's egress in that zone | Zonal NAT gateway, one per AZ | Keeps traffic out of cross-AZ charges, at an hourly charge per gateway |
| small dev or lab VPC with tiny traffic and cost is the only goal | NAT instance (self-managed EC2) | No NAT processing fee, but you run patching and failover; not for production |
| high-volume downloads to viewers from S3 or an Application Load Balancer (ALB), MOST cost-effective | Amazon CloudFront in front of the origin | Per-GB rate to viewers, and no charge from an AWS origin to CloudFront |
| large, steady outbound data from AWS to an on-premises data center | AWS Direct Connect with a data transfer out rate | Outbound is billed at the Direct Connect rate, not internet egress |
| few VPCs, one or two links, low volume hybrid connectivity | Site-to-Site VPN | Per connection-hour plus data transfer; no port commitment, so it wins at low volume |
| many VPCs and on-premises networks that need to talk through one hub | AWS Transit Gateway | One attachment per network instead of a peering mesh; watch per-GB processing |
| two VPCs in one Region that exchange steady traffic | VPC peering | No hourly charge, only the path's data rate: the cheapest link between two VPCs |
| workload spans AZs and chatters heavily between tiers | Place the chatty tiers in one AZ (keep HA where it matters) | Same-AZ private-IP traffic is free; cross-AZ is billed both ways for most services |
| many public IPv4 addresses on instances that only serve inbound web traffic | Front them with a load balancer, or move to IPv6 where the app allows | Every public IPv4 address bills hourly, idle or not; one load balancer can replace many |
| a public name must point at a load balancer, CloudFront distribution, Global Accelerator accelerator or S3 static website in the same account | Route 53 alias record | No query charge for alias queries to AWS resources; the hosted zone still bills |
| data copied between Regions for replication or analytics | Keep the consumer in the source Region when possible; else accept the cross-Region rate | Inter-Region data is billed on the outbound side from the source Region |
Correct pattern
REFERENCE PATTERN: a VPC with a private workload subnet in two Availability Zones. Each AZ has its own NAT gateway for internet egress. A gateway endpoint for Amazon S3 keeps S3 traffic off the NAT gateways entirely.
# Gateway endpoint for S3, attached to the private route tables (no hourly or per-GB charge)
aws ec2 create-vpc-endpoint \
--vpc-id vpc-0example \
--vpc-endpoint-type Gateway \
--service-name com.amazonaws.us-east-1.s3 \
--route-table-ids rtb-0private-a rtb-0private-b
# One NAT gateway per AZ, placed in that AZ's public subnet
aws ec2 create-nat-gateway --subnet-id subnet-0public-a --allocation-id eipalloc-0a
aws ec2 create-nat-gateway --subnet-id subnet-0public-b --allocation-id eipalloc-0b
# Private route table in each AZ sends internet-bound traffic to its own NAT gateway
aws ec2 create-route --route-table-id rtb-0private-a \
--destination-cidr-block 0.0.0.0/0 --nat-gateway-id nat-0a
aws ec2 create-route --route-table-id rtb-0private-b \
--destination-cidr-block 0.0.0.0/0 --nat-gateway-id nat-0b
The endpoint adds the S3 route itself, as a prefix-list route (a managed list of the service's IP ranges) that is more specific than 0.0.0.0/0. So S3 traffic from private subnets uses the gateway endpoint. Everything else uses the NAT gateway in the same AZ.
Traps
| The trap | Why it fails | Correct pattern |
|---|---|---|
| "One central NAT gateway in one AZ is cheapest" for a multi-AZ workload | Fewer gateways means a lower hourly bill, but other AZs pay cross-AZ charges both ways and AZ resilience is lost | One zonal NAT gateway per AZ with workloads, or a regional NAT gateway. Accept the hourly cost of resilience. The cross-AZ charges apply to all egress. |
| Using a NAT gateway for S3 traffic from private subnets | NAT charges per GB on every byte, though a free gateway endpoint could carry it | Add a gateway endpoint for S3 (or DynamoDB) to the private route tables. |
| Choosing an interface endpoint for S3 because "endpoints are cheaper than NAT" | S3 interface endpoints bill per hour per AZ and per GB; the S3 gateway endpoint is free | Gateway endpoint for S3 and DynamoDB. Interface endpoints for other services, when volume justifies them. Most services have no gateway endpoint. |
| Choosing a NAT instance to save money in production | Drops the NAT fee but adds patching and a single point of failure, failing overhead and availability needs | Managed NAT gateway per AZ. A NAT instance also adds EC2 cost and scaling work. Keep NAT instances for labs and very small dev VPCs. |
| Serving high-volume public downloads straight from S3 or EC2 to the internet | Direct egress bills per GB at the internet rate; "MOST cost-effective" wants a cheaper path | Put CloudFront in front of the origin. Transfer from the AWS origin to CloudFront is not charged. |
| Assuming a transit gateway is cheaper than VPC peering for two VPCs | A transit gateway adds hourly attachment and per-GB processing charges; peering has no hourly fee | VPC peering for a few VPCs. Move to a transit gateway when the peering mesh gets hard to manage. |
| Assuming a Site-to-Site VPN is a cheap way to move terabytes a month to AWS | Tunnel throughput is capped and data transfer charges apply, so at volume the per-GB and throughput costs add up | Direct Connect for steady high-volume hybrid traffic. Keep VPN as the low-volume or backup link. Standard data transfer charges apply to all data over it. See task 3.4. |
| Ignoring public IPv4 charges because "it is only an address" | Every public IPv4 address bills hourly, including idle Elastic IPs and running instances' addresses | Share addresses behind a load balancer or NAT gateway. Check the public IPv4 line in the CUR. |
Compare
| Option | Hourly charge | Per-GB charge | Use when |
|---|---|---|---|
| Gateway endpoint (S3, DynamoDB) | None | None | Private access to S3 or DynamoDB in the same Region. Check first. |
| Interface endpoint (PrivateLink) | Per endpoint per AZ | Per GB processed | Private access to other AWS services, or your own, at volume. |
| NAT gateway (zonal) | Per gateway per AZ | Per GB processed, any source or destination | Private egress with one gateway per zone, in that zone. |
| NAT gateway (regional) | Each AZ-hour it is configured in | Per GB processed, any source or destination | Private egress across several zones without a gateway per zone. |
| NAT instance (self-managed) | EC2 instance cost | Normal data transfer; no NAT processing fee | Labs and very small dev VPCs. You own patching and failover. |
| VPC peering | None | Path rate: same-AZ private IP free, inter-AZ and inter-Region billed | Two or a few VPCs that exchange steady traffic. |
| Transit gateway | Per VPC attachment per hour | Per GB processed; none on data from a peering attachment | A hub for many VPCs, VPNs and Direct Connect links. |
| Site-to-Site VPN | Per VPN connection | Data transfer rate for data over the connection | Low-volume hybrid links, or backup for Direct Connect. |
| Direct Connect | Port-hour charge (dedicated or hosted) | Data transfer out at the Direct Connect rate | Steady high-volume hybrid traffic, with consistent latency. |
| CloudFront | None for the distribution itself | Data out to viewers; waived from AWS origins to the edge | Public downloads and web content, especially high volume. |
Two rules settle most comparisons. First, anything that can use a gateway endpoint should, because it is the only free option.
Second, shorten a per-GB path before you buy a bigger link. Keeping traffic in one AZ, caching at the edge or using a private link is almost always the cheaper fix.
Worked exam scenario
Exam scenario
A company runs a web fleet and a batch-processing fleet in a private subnet of a VPC in two Availability Zones. The batch fleet reads and writes objects in an Amazon S3 bucket in the same Region, and it downloads a few hundred gigabytes a day of public packages from the internet. The company wants the LOWEST network cost without increasing operational overhead. Each Availability Zone's download traffic must leave the VPC through a zonal NAT gateway placed in that same zone. Which solution meets these requirements MOST cost-effectively?
- A.Route all traffic through one NAT instance in a public subnet and use it for both S3 and the internet.
- B.Add a gateway endpoint for Amazon S3 to the private route tables, and keep one zonal NAT gateway per Availability Zone for the package downloads.
- C.Replace the S3 traffic with an interface endpoint for S3 in each Availability Zone and move all downloads to a Site-to-Site VPN.
- D.Move the batch fleet to a single Availability Zone and send all traffic through a transit gateway to a shared egress VPC.
Show the walkthrough
- Find the paths. Two kinds of traffic leave the private subnet. S3 traffic stays in the Region and has a free gateway endpoint. Package downloads go to the internet and need a NAT gateway.
- Read the keywords. "LOWEST network cost" and "without increasing operational overhead" rule out self-managed options and paid links with hourly charges. "Same Region" tells you S3 can use a gateway endpoint.
- Eliminate option a. A NAT instance drops the NAT processing fee, but one self-managed instance would carry all the traffic, S3 included. That adds operational overhead, and the S3 traffic doesn't need it at all.
- Eliminate option c. An interface endpoint for S3 bills per hour per AZ and per GB, while the gateway endpoint is free. A Site-to-Site VPN adds a connection charge and data transfer charges, and doesn't cut the download cost.
- Eliminate option d. A single AZ removes resilience, which the stem did not ask to give up. A transit gateway adds an hourly charge per attachment and a per-GB charge, and cuts neither the S3 nor the download cost.
- Land on option b. The gateway endpoint takes S3 traffic off NAT at no charge. A zonal NAT gateway per AZ handles the downloads as a managed service, with no servers to patch.
- Check the zone rule. Each AZ's traffic leaves through its own gateway, so the same-zone rule is met. That zonal placement rule is what picks a zonal gateway over a regional one.
Answer: B
Check your understanding
Build it
The lab builds private subnets in two Availability Zones, with a gateway endpoint for S3 and a NAT gateway per AZ. It also shows why an interface endpoint for a gateway-only service fails. Open the lab: Network cost.
Key takeaways
- Data transfer is priced by direction and path. Into AWS is free, same-AZ private-IP traffic is free, cross-AZ is mostly billed both ways, and internet egress is the expensive path.
- A NAT gateway bills per hour plus per GB processed in either direction. Put one in each Availability Zone with workloads.
- A gateway endpoint for S3 or DynamoDB is free, so use it before any NAT or interface endpoint path.
- Interface endpoints, transit gateways and VPN connections charge per hour and per GB. Model the volume before you choose them.
- For high-volume internet egress, use CloudFront. For steady high-volume hybrid traffic, use Direct Connect.
- Cost follows direction and path: keep traffic in one Availability Zone where you can, gateway endpoints for S3 and DynamoDB, NAT for low-volume egress, CloudFront or Direct Connect for volume.
Hands-on lab: Put Private Traffic on a Gateway Endpoint, Not NAT
Sources
- https://docs.aws.amazon.com/vpc/latest/userguide/nat-gateway-pricing.html
- https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html
- https://docs.aws.amazon.com/vpc/latest/userguide/nat-gateways-regional.html
- https://docs.aws.amazon.com/vpc/latest/userguide/VPC_NAT_Instance.html
- https://aws.amazon.com/vpc/pricing/
- https://docs.aws.amazon.com/vpc/latest/privatelink/vpc-endpoints-s3.html
- https://docs.aws.amazon.com/vpc/latest/privatelink/vpc-endpoints-ddb.html
- https://docs.aws.amazon.com/vpc/latest/privatelink/concepts.html
- https://aws.amazon.com/privatelink/pricing/
- https://docs.aws.amazon.com/vpc/latest/peering/vpc-peering-basics.html
- https://docs.aws.amazon.com/vpc/latest/tgw/what-is-transit-gateway.html
- https://aws.amazon.com/transit-gateway/pricing/
- https://docs.aws.amazon.com/cur/latest/userguide/cur-data-transfers-charges.html
- https://aws.amazon.com/ec2/pricing/on-demand/
- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html
- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html
- https://aws.amazon.com/cloudfront/pricing/
- https://aws.amazon.com/directconnect/pricing/
- https://aws.amazon.com/vpn/pricing/
- https://aws.amazon.com/global-accelerator/pricing/
- https://docs.aws.amazon.com/global-accelerator/latest/dg/introduction-pricing.html
- https://docs.aws.amazon.com/vpn/latest/s2svpn/VPC_VPN.html
- https://docs.aws.amazon.com/vpn/latest/s2svpn/VPNTunnels.html
- https://docs.aws.amazon.com/directconnect/latest/UserGuide/dedicated_connection.html
- https://docs.aws.amazon.com/directconnect/latest/UserGuide/hosted_connection.html
- https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resource-record-sets-choosing-alias-non-alias.html
- https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/Route53Pricing.html
- https://aws.amazon.com/route53/pricing/
- https://docs.aws.amazon.com/vpc/latest/userguide/configure-subnets.html
- https://docs.aws.amazon.com/vpc/latest/privatelink/gateway-endpoints.html
- https://docs.aws.amazon.com/cur/latest/userguide/what-is-cur.html
Last reviewed