VPC Tutorial #4 : How to set-up VPC Peering a step-by-step guide!!


In this article we are going to set-up VPC peering between two different regions ie. us-east-1 and ap-south-1. You can follow this article make some changes if you want to create peering between same regions or with different accounts too!!

What is Inter-Region VPC Peering?

Inter-region VPC peering allows you to connect VPCs in different AWS regions, enabling the transfer of data using private IP addresses across regions. AWS handles the traffic over its backbone network, ensuring security and low latency, without requiring an internet gateway, NAT gateway, or VPN.

This feature is useful for connecting multi-region applications or data replication between regions. In our case, we will configure it to allow private subnet communication only, meaning all traffic between the VPCs will flow through private IPs, not over the public internet.


Setting Up VPC Peering Between Two VPCs in AWS

In this tutorial, we will create two VPCs, configure subnets, Internet Gateways, route tables, and then establish the peering connection between them. Architecture Overview :

follow the simple 7 step below process to master the peering connection!!


Step 1:

Creating peering-vpc-1 in us-east-1:

  1. Navigate to the VPC Dashboard.

  2. Click on Create VPC.

  3. Set the CIDR block to 11.0.0.0/16 and name it peering-vpc-1.

  4. Click Create.

Creating Peering-vpc-2ap-south-1:

  1. Switch to the ap-south-1 region.

  2. Repeat the process, Set the CIDR block to 12.0.0.0/16 and vpc name

    Peering-vpc-2.


Step 2: Create Subnets in Each VPC

Next, we will create private subnets in each VPC.

A. For peering-vpc-1 (us-east-1):

  1. Go to Subnets and click Create Subnet Public-subnet-peering-vpc-1.

  2. Choose peering-vpc-1.

  3. Set the CIDR block to 11.0.1.0/24.

  4. Attached IGW internet gateway

B. For peering-vpc-2 (ap-south-1):

  1. Repeat the process in ap-south-1.

  2. Set the CIDR block to 11.1.0.0/24.

  3. s.


Step 3: Create Route Tables

To ensure traffic flows between the VPCs, we need to update the route tables in both regions.

A. Create RT in VPC-A (us-east-1):

  1. Go to Route Tables.

  2. create route table rt-peering-vpc-1.

  3. Associate RT to subnet .

  4. modify RT as below..

B. Create RT in VPC-B (us-west-2):

  1. Switch to us-west-2 and go to Route Tables.

  2. create route table rt-peering-vpc-2.

  3. Associate RT to subnet

  4. Modify RT for IGW and Peering connection


Step 5: Create peering connection

  1. Create Peering connection “demo-peering-connection”

  2. Select Requester VPC ID

  3. Select My Account and Region Another region

  4. Provide VPC ID (Accepter)

  5. Hit Create peering connection.

  6. A VPC peering connection pcx-0*****0 / demo-peering-connection has been requested.

  7. Switch to ap-south-1 → vpc2 and accept the request

  8. Now you need to update/modify rt (mentioned in step 3 screen shot)


Step 6: Configure Instances

For Instances in VPC-A:

  1. Launch Ec2 instance in vpc1

    1. Add user data →

      #!/bin/bash

      apt-get update

      apt-get install nginx -y

      echo "hostname is $(hostname)" >/var/www/html/index.html

    2. Connect to ec2 instance by SSM/terminal.

For Instances in VPC-B:

  1. Launch EC2 instance in vpc2.

    1. Add user data →

      #!/bin/bash

      apt-get update

      apt-get install nginx -y

      echo "hostname is $(hostname)" >/var/www/html/index.html

  2. Connect to ec2 instance by SSM/terminal.


Step 7: Test peering :

  1. test “curl public ip” to each other!!

  2. Success !!


Key Takeaways

  1. Simplified Network Connections
    "VPC Peering enables private communication between VPCs, allowing resources to talk to each other without using the internet, which enhances security and lowers latency."

  2. Essential Use Cases
    "Common scenarios for VPC Peering include cross-account connections, resource sharing, and enabling secure access between separate environments like development and production VPCs."

  3. Configuration Essentials
    "For VPC Peering to work correctly, both route tables and security groups must be updated to allow the traffic you want to pass between VPCs. Skipping these configurations is a common mistake."

  4. Cost and Performance Benefits
    "VPC Peering doesn't have hourly costs, only data transfer fees, and it keeps data within AWS's high-speed backbone network, making it ideal for workloads needing consistent performance and low latency."


10
Subscribe to my newsletter

Read articles from Shivprasad Waghmare directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shivprasad Waghmare
Shivprasad Waghmare

"Accidental DevOps Engineer | 7+ Years of Experience | Exploring AWS, Kubernetes, Terraform, Docker, Jenkins | Passionate about automating cloud infrastructure | Let’s explore the world of DevOps together!"