Sub topic 3
Why VPC peering stops scaling
This chapter assumes you know CIDR blocks, subnets, route tables, and security groups, and that you have used the AWS CLI or console. You will learn what a VPC peering connection is, why it does not pass traffic through a third VPC, and how the number of connections and routes grows as you add VPCs.
What a peering connection is
A VPC peering connection is a one-to-one network link between two VPCs. The VPCs can be in the same account or in different accounts, and in the same Region or in different Regions. Traffic flows over the AWS network and does not cross the public internet.
Peering is not a device in the data path. There is no gateway, no appliance, and no single point of failure to size. For that reason it has no hourly charge, and you pay only for data transfer. For two or three VPCs it is often the simplest and cheapest option.
Creating a connection takes a request and an acceptance:
- The owner of the requester VPC creates the peering connection.
- The owner of the accepter VPC accepts it. In the same account this is still a separate step.
- Both sides add a route in each subnet route table that needs to reach the other VPC.
- Security groups and network ACLs are adjusted to allow the traffic.
aws ec2 create-vpc-peering-connection \
--vpc-id vpc-0aaa1111bbb22222c \
--peer-vpc-id vpc-0ddd3333eee44444f
aws ec2 accept-vpc-peering-connection \
--vpc-peering-connection-id pcx-0123456789abcdef0
aws ec2 create-route \
--route-table-id rtb-0123456789abcdef0 \
--destination-cidr-block 10.1.0.0/16 \
--vpc-peering-connection-id pcx-0123456789abcdef0The last command only configures one side. The peer VPC needs a matching route back to the first VPC's CIDR, or replies will have nowhere to go.
Peering is non-transitive
Peering is non-transitive. If VPC A is peered with VPC B, and VPC B is peered with VPC C, then A cannot reach C through B. Traffic must be sourced from or destined to an address inside one of the two VPCs that make up a connection.
This is a deliberate design choice. A peering connection carries traffic for the two VPC address ranges and nothing else. It does not behave like a router that forwards packets for others. The same rule blocks several tempting shortcuts:
- Edge-to-edge routing. If VPC B has a VPN connection, an internet gateway, or a NAT gateway, VPC A cannot use it through the peering connection. Each VPC needs its own.
- Gateway endpoints. A VPC cannot use another VPC's gateway endpoint for Amazon S3 across a peering connection.
- Forwarding with an instance. Running a router or proxy instance in VPC B does not fix this, because the source and destination addresses of the forwarded traffic do not belong to the peered pair in the way the connection requires. AWS does not support it as a design.
The only way to let A reach C with peering is to peer A directly with C.
Why a full mesh grows quickly
Since every pair that needs to communicate needs its own connection, connecting every VPC to every other VPC is a full mesh. The number of connections for n VPCs is n × (n − 1) / 2.
| VPCs | Peering connections | Routes to add (one per peer, per route table) |
|---|---|---|
| 3 | 3 | 2 per route table |
| 5 | 10 | 4 per route table |
| 10 | 45 | 9 per route table |
| 20 | 190 | 19 per route table |
| 50 | 1,225 | 49 per route table |
Connection count grows with the square of n, but the work is larger than that. Each new VPC needs a connection to every existing VPC, and every existing VPC needs a new route to it in each route table that must reach it. Adding the 21st VPC to a mesh of 20 means 20 new connections, 20 acceptances, and updates to 20 other VPCs' route tables.
Quotas and other limits
Several limits turn the growth above into hard stops.
- Active peering connections per VPC. The default quota is 50 and can be raised to a maximum of 125. A VPC cannot be in a mesh with more peers than this.
- Route table entries. Each route table has a default quota of 50 non-propagated routes, which can be raised to 1,000. One route per peer, repeated in every route table, consumes this quota. Larger values may affect network performance.
- Security group rules. If each peer's CIDR gets its own rule, you spend rules in security groups too. In the same Region, a security group rule can reference a peer VPC's security group instead of a CIDR, which keeps rules shorter.
Check the current values in Service Quotas before you plan, because AWS adjusts them over time.
Overlapping address ranges
Peering requires that the two VPCs have no overlapping IPv4 CIDR blocks. A peering connection between VPCs with overlapping ranges cannot be created. In a mesh, every VPC must be disjoint from every other peer. If two VPCs that both need to be peered with a third use the same range, it is impossible to route to them unambiguously.
Also note that peering does not allow more specific routes to override this. Planning a non-overlapping address scheme before you grow is much easier than fixing it later. A later chapter covers what to do when ranges already overlap.
Operational drawbacks
Besides the arithmetic, a large mesh is awkward to run:
- No central view. Every connection is owned and accepted by the VPC owners, so routing intent is spread across many route tables. An audit has to read all of them.
- No segmentation control point. You cannot say that a group of VPCs may talk to each other but not to another group, except by omitting connections or by writing security rules in every VPC.
- No on-premises sharing. Because peering is non-transitive, a Site-to-Site VPN or Direct Connect gateway attached to one VPC cannot serve the others. Each VPC needs its own on-premises link.
- Change risk. Adding a VPC touches many existing VPCs, so a mistake in one route table can break traffic that was previously working.
When peering is still the right choice
Peering is not obsolete. Consider it when:
- You connect a small, stable number of VPCs, roughly fewer than five.
- You need the lowest latency and no per-gigabyte processing charge beyond normal data transfer, since there is no intermediate hop to pay for.
- Throughput is high and you do not want any bandwidth limit other than the instance's own network capability.
- The relationship is a simple pair, such as a shared-services VPC and one application VPC.
When the VPC count grows, when you need central control of routing, or when you want to share one on-premises connection, move to a hub design. The next chapters introduce AWS Transit Gateway, which replaces the mesh with one attachment per VPC.
Quick reference
| Property | VPC peering |
|---|---|
| Topology | Point to point between two VPCs |
| Transitive routing | No |
| Overlapping CIDRs | Not allowed |
| Central route control | No, routes live in each VPC |
| Hourly charge | None |
| Typical fit | Few VPCs, simple pairs |
Exercise
A company has 12 VPCs and wants every VPC to reach every other VPC using peering. How many peering connections are needed, and why does adding a peering connection from VPC A to VPC B and one from VPC B to VPC C not let A reach C?
Show answer
A full mesh of 12 VPCs needs 12 × 11 / 2 = 66 peering connections. Peering is non-transitive: a connection only carries traffic whose source or destination is in one of the two VPCs it joins, so A reaching C through B is not permitted. A and C need their own direct connection.
Exercise
You peered VPC A (10.0.0.0/16) with VPC B (10.1.0.0/16) and added a route in A's route table for 10.1.0.0/16 through the peering connection. Instances in A still get no replies from B. What is the most likely cause, and what is the fix?
Show answer
B's route table has no route for 10.0.0.0/16 pointing at the peering connection, so replies are dropped. Add that return route in the relevant B subnet route tables, and check that B's security groups and network ACLs allow traffic from 10.0.0.0/16.