DEV Community

amalkabraham001 for AWS Community Builders

Posted on

Creating a VPC Peering Connection

Hi Friends,

Let us learn about the basics of VPC peering, limitations of vpc peering and how can we create a vpc peering connection between two VPCs.

What is VPC peering

A VPC peering connection is a networking connection between two VPCs that enables you to route traffic between the VPCs using private IPv4 addresses or IPv6 addresses.The instances in these VPCs can communicate each other. VPCs can be created within the same AWS Account or with another AWS Account. AWS doesn't charge you for creating a Peering connection however you need to pay for the traffic flow between the VPCs.
VPC Peering Diagram

Let us assume that you have created the VPC peering for your VPCs residing in the same region and in the same account. You are trying to connect between instance A in VPC 1 and instance B in VPC 2. If both the instances are in the same AZ, then the connectivity charges is zero as your traffic is not flowing outside of the AZ.
Leverage Transit gateway if you need multiple VPCs to interconnect rather than creating peering connections.

Limitations of VPC Peering

  1. VPC peering doesn't support transitive peering. :- Let us assume that you have three VPCs. You had created a peering between "VPC A and VPC B" and "VPC B and VPC C". Don't expect that you can connect an instance in VPC A to an instance running in VPC C.

  2. Edge to Edge Routing is not supported :- Let us assume that you have created a peering connection between VPC A and VPC B. VPC A has connected to an internet gateway or a VPN gateway. The instances in VPC B, cannot use an Internet gateway or VPN gateway connected to VPC A for the traffic Flow.

  3. Overlapping CIDR blocks are not supported :- Your VPCs should not have the same or overlapping IP Address ranges.

  4. You cannot create multiple VPC peering connections between 2 VPCs at the same time.

  5. Mind your VPC Peering connection quotas

Creating a VPC Peering Connection

In this blog, I am going to create a VPC peering connection between my two VPCs located in the same region and same account.

  • Navigate to the AWS portal--> VPC

  • Search for Peering connections under the virtual private cloud section.

VPC peering connection page

  • The peering connection page will appear. Click on "create peering connection" from the top right corner.

peered connections page

  • In the create peering connection page, provide the details as below

new peering connection

  1. Name of your peering connection

  2. The VPC ID of the requester

  3. Specify the AWS Account of the 2nd VPC to which you need to create the peering connection

1.Specify the AWS Region of the 2nd VPC to which you need to create the peering connection

  1. The VPC ID of the Accepter

  2. Provide tags if any and click on Create peering connection

Once you create the peering connection, you need to accept the peering connection. If you are connecting to a VPC in a different account, navigate to that account and accept the peering connection request
Acceptance pending
Verify the settings and click accept request

Accept VPC request
You will get a confirmation once the request has been accepted.

VPC Peering request confirmed

s Create Route Table

An important activity to perform as part of the VPC peering activity is to edit your route tables and add the cross VPC routing.

Routing table structure
The below diagrams shows the routing tables created for my VPCs.

VPC A routing table
VPC B routing table

s Testing the connection

Our VPC peering is done, now it time to test it. I had connected to VM1 in VPC A and tried an ICMP ping to my VM2 located in VPC B. Note: I have enabled security group inbound rules for the ICMP traffic flow._

Ping test across VPCs

Hope this short blog helps you to understand what is VPC peering and how to create a VPC peering connection.

Top comments (0)