Before we actually talk about VPC Peering, let’s talk about why there is a need for a VPC peering connection. In a real-world project, where there are multiple AWS accounts and also multiple Environments like Dev, Stage, Test, and Prod. Generally, to differentiate resources, each Environment is mapped with a VPC.
When there are multiple VPCs in the same/different AWS Regions/Accounts and they need to communicate with each other, there has to be a VPC Peering connection. Without a VPC Peering connection, they can’t communicate as each VPC has its own private address space(CIDR).
VPC Peering connection can’t be established during the following scenarios
If you have to establish a peering connection between two VPC, you’ll have to create a Peering request first. The VPC that initiates the Peering connection is called Requestor and the VPC that has to accept the peering request is treated as an Acceptor VPC. After the Acceptor VPC accepts the VPC Peering connection, the connection is established and you have to configure the Route table of both VPCs add a route with peering connection id. The route tables for each VPC point to the relevant VPC peering connection to access the entire CIDR block of the peer VPC. Now, after these changes are made traffic can flow from one VPC to the other. Below is an example of Route tables for VPC A and VPC B with a peering connection.
Route table | Destination | Target |
---|---|---|
VPC A | 172.16.0.0/16 | Local |
10.0.0.0/16 | pcx-11112222 | |
VPC B | 10.0.0.0/16 | Local |
172.16.0.0/16 | pcx-11112222 |