Network Cost Optimization and AWS Client VPN
Overview
Network charges are among the most surprising items on an AWS bill. You pay for NAT gateway hours and gigabytes processed, data transfer between Availability Zones and Regions, data going out to the internet, interface endpoints, public IPv4 addresses and Transit Gateway attachments and traffic. SOA-C03 includes the skill "optimize the cost of network architectures", and AWS Client VPN is an in-scope service for secure remote access to VPC resources.
Think of electricity. A kitchen full of appliances is fine, but leaving a heater on in an empty room (an idle NAT gateway), running cables between distant buildings (cross-AZ traffic) or leaving a tap running (large public downloads from S3 through NAT) quietly inflates the bill. Fixing it means switching appliances off, putting them closer together and using the cheaper supply line (VPC endpoints, CloudFront).
Client VPN is the staff entrance: remote employees connect to the private network with a managed OpenVPN-based service instead of exposing servers publicly.
Key Concepts
- NAT gateway costs an hourly fee plus a per-GB processing fee; heavy S3/DynamoDB traffic through NAT is a classic overspend. Use gateway endpoints (free) for S3 and DynamoDB.
- Interface endpoints (PrivateLink) cost per hour per AZ plus per GB; worthwhile when they replace NAT for AWS service traffic or give private access to SaaS/services.
- Cross-AZ data transfer is charged in both directions (about $0.01/GB each way); design AZ-aware traffic (same-AZ endpoints, zonal ALB targets, avoid chatty cross-AZ calls) while keeping availability.
- Data transfer out to the internet is tiered; CloudFront is cheaper per GB than direct egress, and origin fetches from AWS to CloudFront are free. Direct Connect has lower transfer rates than internet egress.
- Public IPv4 addresses are charged hourly (including in-use addresses); reduce with private subnets, ALB sharing, IPv6 and VPC IPAM Public IP Insights.
- VPC peering within the same AZ is free of transfer fees (cross-AZ/Region apply); Transit Gateway charges per attachment-hour and per GB processed.
- AWS Client VPN: managed client-based VPN with an endpoint, target network associations (subnets), authorization rules, route table entries and authentication via Active Directory, mutual certificates or SAML federated sign-in.
- Cost tools: Cost Explorer (filter by usage type such as
NatGateway-Bytes,DataTransfer-Regional-Bytes), Cost and Usage Reports + Athena, VPC Flow Logs, and CloudWatch NAT gateway metrics.
Detailed Notes
Where network money goes
| Cost driver | Usage type (Cost Explorer) | Reduction tactic |
|---|---|---|
| NAT gateway processing | NatGateway-Bytes, NatGateway-Hours | S3/DynamoDB gateway endpoints, interface endpoints for chatty services, one NAT per AZ only where needed, remove idle NATs in dev |
| Inter-AZ traffic | DataTransfer-Regional-Bytes | AZ-local endpoints, topology-aware routing, cache locally, compress |
| Internet egress | DataTransfer-Out-Bytes | CloudFront, compression, regional caching, Direct Connect for large steady flows |
| Public IPv4 | PublicIPv4:InUseAddress | Fewer public IPs, ALB/NLB fronting, IPv6, release unattached EIPs |
| Interface endpoints | VpcEndpoint-Hours/Bytes | Consolidate in shared-services VPC, only for needed services |
| Transit Gateway | TransitGateway-Hours/Bytes | Use peering for simple two-VPC pairs, reduce chatty flows |
| Inter-Region | DataTransfer-Regional between Regions | Replicate only what is needed, compress, consider S3 Replication Time Control only if required |
Find the culprit
aws ce get-cost-and-usage --time-period Start=2025-01-01,End=2025-02-01 --granularity DAILY \
--metrics UnblendedCost --group-by Type=DIMENSION,Key=USAGE_TYPE \
--filter '{"Dimensions":{"Key":"SERVICE","Values":["Amazon Elastic Compute Cloud - Compute"]}}'
aws cloudwatch get-metric-statistics --namespace AWS/NATGateway --metric-name BytesOutToDestination \
--dimensions Name=NatGatewayId,Value=nat-0abc --start-time 2025-01-01T00:00:00Z --end-time 2025-01-02T00:00:00Z \
--period 3600 --statistics Sum
To identify which instance and destination drive NAT bytes, enable VPC Flow Logs on the NAT gateway's ENI and query with Athena or CloudWatch Logs Insights:
fields srcAddr, dstAddr, sum(bytes) as total
| filter interfaceId = "eni-0nat"
| stats sum(bytes) as total by srcAddr, dstAddr
| sort total desc | limit 10
Gateway endpoint to remove NAT cost
aws ec2 create-vpc-endpoint --vpc-id vpc-0abc --service-name com.amazonaws.us-east-1.s3 \
--vpc-endpoint-type Gateway --route-table-ids rtb-0private1 rtb-0private2
Gateway endpoints add a prefix-list route; they are free, work only for S3 and DynamoDB, are Regional, and cannot be used from on-premises or other Regions (use interface endpoints for that).
AWS Client VPN
| Component | Purpose |
|---|---|
| Client VPN endpoint | Termination point; defines client IPv4 CIDR (at least /22), server certificate (ACM), authentication, logging |
| Target network association | Links the endpoint to one or more subnets; associate subnets in multiple AZs for availability |
| Authorization rule | Which destination CIDRs which AD groups/users may reach |
| Route table | Routes to VPC, peered VPCs, internet (full tunnel) |
| Split tunnel | Only VPC-bound traffic goes through VPN, the rest uses the local internet |
aws ec2 create-client-vpn-endpoint --client-cidr-block 10.200.0.0/22 \
--server-certificate-arn arn:aws:acm:us-east-1:111122223333:certificate/abcd \
--authentication-options Type=federated-authentication,FederatedAuthentication={SAMLProviderArn=arn:aws:iam::111122223333:saml-provider/idp} \
--connection-log-options Enabled=true,CloudwatchLogGroup=/clientvpn/prod --split-tunnel
aws ec2 associate-client-vpn-target-network --client-vpn-endpoint-id cvpn-endpoint-0abc --subnet-id subnet-0abc
aws ec2 authorize-client-vpn-ingress --client-vpn-endpoint-id cvpn-endpoint-0abc --target-network-cidr 10.0.0.0/16 --authorize-all-groups
Troubleshooting Client VPN:
| Symptom | Cause |
|---|---|
| Connected but cannot reach VPC | Missing authorization rule, route entry, or security group on the target resources (the endpoint ENI uses the subnet's default SG unless set) |
| Cannot reach internet in full-tunnel | No route 0.0.0.0/0 plus authorization rule and NAT path |
| Connection fails | Certificate mismatch, client config outdated, SAML assertion error; check connection logs |
| Billed unexpectedly | Charged per association-hour and per active connection-hour; disassociate unused subnets |
Client VPN is for people; Site-to-Site VPN or Direct Connect connects networks, and Systems Manager Session Manager or EC2 Instance Connect Endpoint avoid a VPN for administrative access.
Real World Example
Scenario – surprise NAT bill. Cost Explorer shows NatGateway-Bytes doubled to 80 TB in a month. Flow Logs on the NAT ENI reveal that a nightly analytics job pulls terabytes from S3 through the NAT gateway.
The operator adds an S3 gateway endpoint to the private route tables; NAT processing charges for that traffic vanish immediately. They also move a chatty cross-AZ microservice pair into zone-aware routing, consolidate dev NAT gateways to one per VPC, and front public downloads with CloudFront. Remote contractors reach internal tools through Client VPN with SAML sign-in, split tunneling and authorization rules limited to the tools subnet. Monthly network cost drops 38%.
Architecture Diagram
- 1Analyse cost by usage type in Cost Explorer or CUR and Athena.
- 2Use Flow Logs on the NAT ENI to identify the heaviest talkers and destinations.
- 3Route AWS service traffic through gateway or interface endpoints instead of NAT.
- 4Reduce cross-AZ and internet egress with AZ-aware design and CloudFront.
- 5Provide remote access through Client VPN or Session Manager with least-privilege rules.
Best Practices
- ✓Create S3 and DynamoDB gateway endpoints in every VPC with private subnets.
- ✓Track
NatGateway-Bytes,DataTransfer-Regional-Bytesand public IPv4 usage in Cost Explorer and with Budgets alerts. - ✓Serve internet-bound content through CloudFront and compress responses.
- ✓Keep traffic AZ-local where it does not harm resilience and avoid unnecessary cross-Region replication.
- ✓Configure Client VPN authorization rules, split tunneling, SAML or AD auth and connection logging; remove unused associations.
Common Interview Questions
Exam Tips
SOA-C03 focus
- Private instances pulling lots of S3 data and high NAT cost -> S3 gateway endpoint.
- Cross-AZ traffic is charged both directions; same-AZ traffic using private IPs is free.
- Cheaper internet delivery -> CloudFront; large steady hybrid flows -> Direct Connect.
- Remote workforce access to VPC -> Client VPN; configure authorization rules, routes and SAML/AD/certificate auth.
Finished this lesson?
0 of 46 lessons done · 0% of the course

