Sub topic 2
Cutting NAT Traffic with VPC Endpoints
Assume you understand VPCs, subnets, route tables, Availability Zones (AZs), and basic AWS CLI commands. The main goal is to keep AWS-bound traffic on private paths instead of sending it through a NAT gateway.
Use VPC endpoints for AWS services
A NAT gateway lets resources in private subnets reach public AWS service endpoints. It charges per gigabyte processed, so high-volume S3 or DynamoDB traffic can create unnecessary cost.
A gateway VPC endpoint changes the route. It adds service-prefix routes to selected route tables. Traffic then stays on the AWS network and avoids NAT gateway data-processing charges.
| Endpoint type | Common use | Main cost consideration |
|---|---|---|
| Gateway | S3 and DynamoDB | No hourly endpoint or data-processing charge |
| Interface | Many other AWS services | Hourly cost per AZ and per-GB processing |
Create an S3 gateway endpoint and associate it with the route table used by the private subnet:
aws ec2 create-vpc-endpoint \
--vpc-id vpc-0123456789abcdef0 \
--vpc-endpoint-type Gateway \
--service-name com.amazonaws.us-east-1.s3 \
--route-table-ids rtb-0123456789abcdef0Keep private traffic in one AZ
Use private IP addresses for communication between resources whenever possible. Public addresses can route through extra network components and may add transfer charges.
Place chatty, tightly coupled resources in the same AZ when that does not reduce availability. For example, an application and its cache can communicate through private IPs without crossing an AZ boundary.
Reduce inter-AZ traffic
Cross-AZ traffic can incur regional data-transfer charges. Reduce it by locating frequently communicating components together, using AZ-local load-balancer targets where practical, and avoiding unnecessary cross-AZ replication. Keep multi-AZ deployment for resilience, but measure whether high-volume flows justify redesign.
Serve content through CloudFront
CloudFront caches content at edge locations. Cache hits avoid repeated transfers from the origin and can reduce internet egress from services such as S3 or a load balancer. Enable compression for suitable text responses and set cache policies that allow safe, reusable objects.
Exercise
A private application downloads large objects from S3 through a NAT gateway. What change should you test first?
Show answer
Create an S3 gateway VPC endpoint, associate it with the application's route table, and confirm that the S3 route no longer uses NAT.