AWS-VPC Peering across Two Regions

A virtual private cloud (VPC) is a virtual network dedicated to your AWS account. It is logically isolated from other virtual networks in the AWS Cloud.

A VPC peering connection is a networking connection between two VPCs that enables you to route traffic between them using private IPv4 addresses or IPv6 addresses. Instances in either VPC can communicate with each other as if they are within the same network. You can create a VPC peering connection between your own VPCs, or with a VPC in another AWS account.

For example, if you have more than one AWS account, you can peer the VPCs across those accounts to create a file sharing network. You can also use a VPC peering connection to allow other VPCs to access resources you have in one of your VPCs. When you establish peering relationships between VPCs across different AWS Regions, resources in the VPCs (for example, EC2 instances and Lambda functions) in different AWS Regions can communicate with each other using private IP addresses, without using a gateway, VPN connection, or network appliance.

Pricing for a VPC peering connection There is no charge to create a VPC peering connection. All data transfer over a VPC Peering connection that stays within an Availability Zone (AZ) is free. Charges apply for data transfer over a VPC Peering connections that cross Availability Zones and Regions

Creating two VPC in two different regions.and then established a connection between them and then create two EC2 and test their connectivity in both the VPC

Region 1- Virginia

— — — — — — — — — — — — —

* Create VPC in one region (Virginia region)

* Create subnet -1

  1. Create subnet associated with VPC-1

2. Enter Details and click on create button

* Create an Internet gateway

1. Click on Internet Gateway

2. Enter name and click on create

3. Select created internet gateway and attach to VPC-1

* Create Route table

1. Now create Route table and select VPC-1

b. Click on Routes section and enter internet gateway at 0.0.0.0/0

c. Associate subnet-1 into subnet association section as follows

* Creating EC2 Instance in Virginia region

  1. Go to EC2 dashboard and click on launch instance

2. Edit Network setting as

VPC= VPC-1

subnet = subnet-1

Auto assign public ip =enable

3. In security group SSH ,HTTP ,HTTPs should be selected

4. Click On launch Instance

5. Click on instance and edit inbound rule in security group

5. Allow All ICMP -IPv4 i.e ICMP protocol

6. connect to instance-virginia

Part II

Region 2 - Mumbai

— — — — — — — — — — — — —

* Create VPC in another region (Mumbai region)

* Create subnet-2

  1. Create subnet associated with VPC-2

2. Enter Details and click on create button

* Create Internet gateway

1. Click on Internet Gateway

2. Enter name and click on create

3. Select created internet gateway and attach to VPC-2

* Create Route table

a. create Route table and select VPC-2

b. Click on Routes section and enter internet gateway at 0.0.0.0/0

c. Associate public subnet into subnet association section as follows

* Creating EC2 Instance in Mumbai region

  1. Go to EC2 dashboard and click on launch instance

2. Edit Network setting as

VPC= VPC-2

subnet = subnet-2

Auto assign public ip =enable

3. In security group SSH ,HTTP ,HTTPs should be selected

4. Click on launch Instance

5. Click on instance and edit inbound rule in security group

6. Allow All ICMP -IPv4 i.e ICMP protocol

7. Connect to instance-Mumbai and use command

Command : ping <private ip of Virginia region instance>

Result : As both instances are in different VPC ,they will not connect with each other

  • Solution for connecting Instances with Different VPC is VPC Peerring

VPC Peering

  1. Click on peering connection

  2. Enter name

  3. Select Vpc -1 to peer with

  4. Select Account or Region as per your requirement

Here both VPC are in different region but with same account so select “My Account “ and “Another region”

5. Select Region name and Paste VPC ID (refer next point ) of Mumbai region VPC

6. Go to Mumbai region -> Go to Vpc -> Select VPC-2 ->Copy VPC-ID and paste in above info

7.Click on create peering connection button

8. Peering connection get created

9. Now Go to Mumbai region and then in peering connection

10. Click on actions

11. Select “Accept request”

12. click on Accept request and peering connection is now active

* Edit Route Table

  1. Go to Virginia region and Select Route-1

2.Click on Routes section and enter peering connection at 192.168.0.0/16 (VPC CIDR of vpc-2)

— — — — — — — — — — — — — —*— — — — — — — — — -* — — — — — — — — — — — —

  1. Go to Mumbai region and Select Route-2

2.Click on Routes section and enter peering connection at 10.0.0.0/16 (VPC CIDR of vpc-1)

* Connect Both Instance and test their connectivity in both the VPC

  1. Now Connect to Instance-Mumbai

Command : ping <private ip of Virginia region instance>

Result:

2.Now Connect to Instance-Virginia

Command : ping <private ip of Mumbai region instance>

Result:

Thanks For Reading.......... for more blogs please follow

0
Subscribe to my newsletter

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

Written by

Haresh Prajapati
Haresh Prajapati