How to create a VPC Peering between 2 VPCs on AWS

A VPC peering connection is a connection between two VPCs that enables you to route traffic between them. We can create a VPC peering connection between our VPCs, or with a VPC in another AWS account. The VPCs can also be in different regions.

We can peer the VPCs across accounts to create a network filesystem and we can also use a VPC peering connection to allow other VPCs to access resources we have in one of our VPCs.

Before we create a VPC Peering connection, let's understand its steps in brief.

  1. The VPC from which we create a Peering connection is called a Requester VPC.
  2. The VPC in which we accept the Peering connection is called the Accepter VPC.
  3. The one who created or accepts the Peering connection is called the Owner.
  4. To create a VPC Peering connection, the owner of the requester VPC sends a request to the owner of the accepter VPC.
  5. To accept the connection, the owner of the accepter VPC accepts the VPC peering connection request sent by the requester.
  6. To allow the flow of traffic between the VPCs using private IP addresses, the owner of each VPC in the VPC peering connection must manually add a route to one or more of their VPC route tables.

In this article, I shall be creating an inter-region VPC Connection. I have one VPC in the Paris region and another in the N. Virginia region. Both of them have different CIDR blocks.

Note: We cannot create a VPC peering connection between VPCs that have matching or overlapping IPv4 or IPv6 CIDR blocks.

Pre-requisites

  1. AWS Account (Create if you don’t have one).
  2. 2 VPCs in 2 different regions. (Click here if you want to learn to create VPC)

What will we do?

  1. Login to AWS.
  2. Create a VPC Peering Connection
  3. Add Routes in Route Tables

Login to AWS

Click here to go to AWS Login Page.

When we hit the above link, we will see a web page as follows where we are required to login using our login details.

Login to AWS

Once we login into AWS successfully, we will see the main console with all the services listed as follows.

AWS Management Console

Create a VPC Peering Connection

To create a VPC Peering connection between 2 VPCs, click on Services in the top left of the screen and search for VPC and open it.

VPC Peering Connection

You see the VPC Dashboard for the region Paris. Click on VPCs to see the VPCs available in the current region i.e. Paris region.

VPC Dashboard

You see that there are 2 VPCs available, 1 is the default VPC and the other one is created by me. You should also have your VPC created. Keep the default VPC untouched.

Add VPC

Now, open the VPCs in the other region in a new tab, here I have another VPC in the N. Virginia region that needs to peer with the one in the Paris region.

Second VPC

So now, we have two tabs with VPCs in 2 different regions.

Go back to the 1st tab to create a VPC Peering connection in Paris region and click Peering Connection in the left panel and then click on "Crete Peering Connection"

Create Peering Connection

Add a name to the peering connection, select a local VPC from the Paris region, and select a VPC from another Region. Click on "Create Peering Connection" to proceed.

Peering details

You will get a message that the VPC Peering Connection has been created. But this is not enough.

Now we need to accept the connection from the VPC in another region.

Connection created successfully

See the status of the connection in the Paris region, it is Pending Acceptance. Now we need to accept the peering connection in another region.

List of connections

Switch the tab, go to N. Virginia region, under Peering Connection select the Peering Connection request and click on Actions -> Accept Request.

Peering connection request

Here on the confirmation dialogue box, click on "Yes, Accept" to accept the connection.

Accept peering request

The request has been accepted successfully, but this is not enough.

Now we need to add routes in the Route Tables of both the VPCs.

Peering successful

Stay in the N. Virginia Region, click on Route Table in the left panel. You will see the Route Tables.

Routes table

Select the route table which has VPC ID of the VPC which has just been peered. 

Click on Routes tab and Edit Routes.

Routes tab

Enter the CIDR of the VPC from Paris Region, select the VPC Peering Connection which we have just created and click on "Save routes"

CIDR of the VPC

Perform the same steps for other route tables in the same region which belong to our VPC. 

Edit Routes

Now, go to the Paris region and click on the Route Table to see the Route tables.

Routes table

Select the Route Table with VPC ID from which we created a VPC Peering Connection. Click on Route tabs --> Edit Routes

 Edit routes

Add CIDR of the VPC in N. Virginia region and select the VPC Peering connection we created in Paris and click on "Save Routes"

Save routes

Perform the same steps with the route table which belongs to our VPC and click on Save Route.

Set second route

Once you have done this, added routes in each route table of the VPC we used to create a VPC Peering Connection, our task is done and Peering has been completed.

Conclusion

In this article, we saw how to create a VPC Peering Connection in one region and accept the peering request in another region. We saw how routes need to be added in each route table associated with our VPC in both regions.

Share this page:

0 Comment(s)