How to Create AWS VPC Peering Connection Step-by-Step

VPC peering allows you to connect two VPCs in the same or different AWS accounts. It operates over the AWS network backbone, ensuring low-latency and high-bandwidth communication between the peered VPCs.

When you create a VPC peering connection, you need to choose the “Requester VPC” and “Accepter VPC.” The requester initiates the peering request, while the accepter approves it. This bidirectional connection enables private IP address communication between instances in the peered VPCs.

Diagram showing VPC Peering setup on Amazon AWS

Regarding VPC peering in AWS cloud, there are several options and circumstances:

  • Two or more VPCs can be connected to one another within the same account.
  • Two or more VPCs in different AWS accounts can be connected.
  • You can establish peering relationships between VPCs in the same account across different AWS Regions.
  • You can establish peering relationships between VPCs in the different accounts across the same AWS Region.

Steps for creating VPC Peering in AWS

Step 1. Create two VPC

You need to have two VPCs. If you don’t have two VPCs then you can learn how to create VPCs here. As you can see I have my two VPCs. One is the requester VPC and another is the accepter VPC. (Just make sure that you use different, non-overlapping subnets for the 2 VPC.)

Screenshot showing two different VPC for creating VPC peering on AWS.

Step 2. Navigate to the VPC Dashboard

Open the Amazon VPC dashboard where you can manage VPC configurations.

Click on “Peering Connections” in the left-hand navigation pane.

Click the “Create Peering Connection” button.

Screenshot showing creating VPC Peering Connection

Type the name of the peering connection.

Select the Requester VPC from the dropdown menu.

Screenshot showing selecting Requester VPC

Also, select the Accepter VPC from the dropdown menu. (If you want to add an accepter from another region then click on “Another Region” or if the VPC is from another account click on “Another Account” and fill in the details required.)

Click on “Create peering connection.”

Screenshot showing selecting accepter VPC and Creating peering connection

Now you will see the message for connection request.

Screenshot showing success message for vpc-peering request

Step 3. Accepting the VPC Peering Request

Click on the Action Button and Select “Accept Request.” (If you have a different region and different account, switch to the respective VPC Peering Connection tab and Accept the request.)

Screenshot showing accepting the vpc-peering connection request

You will see the success message after that.

Screenshot showing success message of VPC peering

Copy the VPC peering id (i.e pcx-XXXXXX), we will need that later.

Step 4. Modify Route Tables of Requester and Accepter VPC

Click on  “Modify my route table now” from the success message box.

Screenshot showing modifying the route tables for the VPC peering connections in the AWS dashboard.

Select the Accepter VPC Route Table and Click on “Edit Routes.”

Screenshot showing editing the routes for the VPC connection

Now click on “Add route.”

In the “Designation” add the CIDR of Requester VPC and in the “Target” add the VPC Peering ID that we have copied from above.

Screenshot showing adding VPC peering connection 

Click on “Save Changes.”

Now also select the Requester VPC route table and add the CIDR of Accepter and VPC Peering ID as above. 

Step 5. Check the Peering Status

Return to the VPC Dashboard.

Verify that the peering status is “active.”

Step 6. Testing the connection

To test the connection I have created two instances, in Requester VPC and in Accepter VPC. Both of them have public and private IP. Then I will curl the accepter instance from the requester instance through the private IP of the accepter instance.

Screenshot showing requester VPC instance with Public IP 
Screenshot showing accepter VPC instance with Public and Private  IP

The user script data that I have used while launching the instance is:

#!/bin/bash

apt update

apt install -y apache2

systemctl start apache2

systemctl enable apache2

echo "Hello world from $(hostname -f)" > /var/www/html/index.html

I will now ssh to the Requester VPC instance and curl the instance in Accepter VPC through its Private IP.

Screenshot showing how to curl the instance through both public and private ip to verify the connection is working.

We have successfully created VPC peering between two VPC. Then we have also tested it by launching EC2 on each VPC by doing the curl on the accepter VPC using private ip. 

Steps for deleting a VPC peering connection

When a peering connection is no longer needed, it’s a best practice to delete it. VPC connections left active that are no longer necessary are a security concern and could incur unnecessary costs, depending on the setup, among other things. Deleting a VPC Peering Connection in AWS is a straightforward process and involves just a few steps.

Note: You can delete a VPC peering connection from either the requester VPC or the accepter VPC. Deleting a VPC peering connection is a significant action that will stop all traffic between the VPCs. It should only be done when necessary and after considering the implications.

Step 1. Open the Amazon VPC console

You can access this directly through the link https://console.aws.amazon.com/vpc/ or by searching for VPC in the AWS Management Console search bar.

Step 2. Go to the ‘Peering Connections’ section

In the navigation pane, click on ‘Peering Connections’.

Step 3. Select the VPC Peering Con