Sub topic 3
Reaching Beyond a VPC
Assume you know CIDR notation, subnets, route tables, and security groups. This chapter connects those pieces to AWS services, other VPCs, and on-premises networks.
Reaching AWS services privately with VPC endpoints
A VPC endpoint provides a private path from a VPC to a supported AWS service. Traffic does not need an internet gateway or NAT gateway.
- A gateway endpoint adds routes for Amazon S3 or DynamoDB. It is configured on route tables.
- An interface endpoint creates private network interfaces in selected subnets. It uses AWS PrivateLink and a security group.
For example, this gateway endpoint keeps S3 traffic on the AWS network:
REGION=us-east-1
VPC_ID=vpc-0123456789abcdef0
PRIVATE_RT_ID=rtb-0123456789abcdef0
aws ec2 create-vpc-endpoint \
--vpc-id "$VPC_ID" \
--vpc-endpoint-type Gateway \
--service-name "com.amazonaws.${REGION}.s3" \
--route-table-ids "$PRIVATE_RT_ID"An interface endpoint usually requires private DNS to be enabled and inbound HTTPS access from the client security group.
Observing traffic with VPC Flow Logs
VPC Flow Logs record metadata about accepted and rejected traffic, including source, destination, ports, protocol, and action. They do not record packet contents. Send logs to CloudWatch Logs or Amazon S3 to troubleshoot routing and audit access.
Connecting VPCs with peering
VPC peering connects two VPCs with private routing. The CIDR ranges must not overlap, and each side needs routes for the other side. Peering is non-transitive: a peered VPC cannot automatically route through another peered VPC.
Scaling with Transit Gateway
Transit Gateway is a regional hub for many VPCs and network connections. It uses route tables to control which attachments can communicate. Use peering for a small number of direct connections. Use Transit Gateway when many VPCs need centralized routing.
Connecting to on-premises
A Site-to-Site VPN creates encrypted tunnels over the internet and is quick to deploy. Direct Connect uses a dedicated connection and offers more predictable performance, but it requires planning and provider facilities. Many designs use Direct Connect as the primary path and VPN as backup.
IPv6 and dual-stack VPCs
A dual-stack VPC assigns both IPv4 and IPv6 addresses. IPv6 subnets can route through an egress-only internet gateway for outbound-only internet access. Security groups and network ACLs need explicit IPv6 rules; IPv4 rules do not protect IPv6 traffic.
Putting it together
A least-privilege design places load balancers in public subnets, applications in private subnets, and databases in isolated subnets. Use endpoints for supported AWS services, security groups for tier-to-tier access, Flow Logs for evidence, and centralized connectivity only when the network requires it.
Exercise
Why can a private application use S3 without a NAT gateway after a gateway endpoint is added?
Show answer
The endpoint adds an S3 route to the private subnet's route table, sending traffic through the AWS network instead of the NAT gateway.