AWS -Virtual Private Cloud

VPC Peering

Need for Peering:

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 Limitations:

VPC Peering connection can’t be established during the following scenarios

  • When there is an overlap between the CIDR blocks of the two VPCs
  • When there is already a Peering connection, the new peering connection can’t be made.
  • Also, tags that created for VPC peering connection are only applied in the account or region in which they are created.
  • When the request is a Transitive connection.
    Example: Consider VPC A and VPC B have a peering connection, likewise VPC B and VPC C have one. Now, based on this no Transitive connection rule, one can’t create a Peering connection between VPC A and VPC C
  • If the peering is inter-region, you cannot create a security group rule that references a peer VPC security group.

Establish a VPC Peering Connection:

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