Sub topic 1
VPC building blocks you will rely on
Later chapters connect VPCs with Transit Gateway and PrivateLink. Both depend on a few VPC basics, so this chapter reviews them and notes where each one matters.
Prerequisites
This chapter assumes you already know the following:
- What a CIDR block is and how to read a prefix such as
10.0.0.0/16. - How to use the AWS CLI or console to inspect VPC resources.
- That security groups and network ACLs both filter traffic.
- What a Network Load Balancer does. PrivateLink chapters use one.
CIDR blocks
A VPC has one or more IPv4 CIDR blocks, for example 10.0.0.0/16. Every subnet takes a smaller range from the VPC block, for example 10.0.1.0/24.
Two VPCs with overlapping ranges cannot be routed to each other through peering or Transit Gateway. Plan non-overlapping ranges now. A later chapter covers what to do when that is impossible.
Subnets and Availability Zones
A subnet lives in exactly one Availability Zone (AZ). A resource such as a network interface is placed in a subnet, so it is also tied to one AZ. Transit Gateway attachments and interface endpoints both ask you to choose subnets, usually one per AZ.
Route tables
A route table is a list of destination and target pairs. Each subnet is associated with exactly one route table. Every route table starts with a local route that covers the VPC's own CIDR. The local route cannot be removed.
When several routes match a packet, AWS picks the most specific one. This is the longest prefix match. A /24 route wins over a /16 route.
Targets you will meet in this tutorial:
| Target | Used for |
|---|---|
| `local` | Traffic inside the VPC |
| Internet gateway | Public internet access |
| Peering connection | One other VPC |
| Transit gateway | Many VPCs and on-premises networks |
| Gateway or interface endpoint | AWS services and PrivateLink services |
Route tables are what make Transit Gateway work. Traffic only reaches the transit gateway if a subnet route points to it.
Run this to see the routes in a VPC:
aws ec2 describe-route-tables \
--filters Name=vpc-id,Values=vpc-0aaa1111bbb22222c \
--query "RouteTables[].Routes[].[DestinationCidrBlock,GatewayId,TransitGatewayId]" \
--output tableSecurity groups and network ACLs
A security group is attached to a network interface. It is stateful, so return traffic is allowed automatically. It only has allow rules.
A network ACL is attached to a subnet. It is stateless, so you must allow traffic in both directions. It supports allow and deny rules.
Routing does not grant access. A route to another VPC only means packets can travel there. The security group and network ACL on the destination must still allow them. Many connectivity problems in this tutorial come from filters, not routes.
Exercise
A VPC route table has 10.0.0.0/16 -> local and 10.0.5.0/24 -> tgw-0123456789abcdef0. Where does a packet for 10.0.5.20 go, and why?
Show answer
It goes to the transit gateway. Both routes match, but the /24 is more specific than the /16, so the longest prefix match chooses it.