Create A VPC Peering

Create A VPC Peering

Create a VPC peering

Hello Everyone

Welcome to CloudAffaire and this is Debjeet

In the last blog post, we have created a VPC endpoint service.

https://cloudaffaire.com/create-a-vpc-endpoint-service/

In this blog post, we are going to create a VPC peering between two VPC in different regions. Below is the configuration diagram for this demo.

Create A VPC Peering

VPC Peering: 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. The VPCs can be in different regions also known as an inter-region VPC peering connection.

In this demo, we are going to create a VPC peering between two VPC hosted in different regions. Below are the prerequisites for this demo

  • One VPC with public and private subnet and EC2 instances hosted inside them.
  • One VPC (Different region from the 1st) with private subnet and EC2 instance hosted inside it.

We have already created the VPC’s and subnets and created EC2 instances inside them.

Instance1 (In public subnet of VPC1):

Create A VPC Peering

Instance2 (In private subnet of VPC1):

Create A VPC Peering

Instance3 (In private subnet of VPC2 hosted in a different region):

Create A VPC Peering

If we try to ping instance3 from instance2, it will not ping as no connection is present. In order to connect instance2 to instance3, you can create a VPC peering between VPC1 and VPC2.

Create A VPC Peering

Next, we are going to create a VPC peering between VPC1 and VPC2.

Create a VPC peering

Step 1: Login to AWS console and navigate to ‘VPC’.

Create A VPC Peering

Step 2: Navigate to ‘Peering Connections’ and click ‘Create Peering Connection’.

Create A VPC Peering

Note: Our VPC1 is hosted in Mumbai region and VPC2 is hosted in Ohio region. Currently, we are creating the peering in the VPC1 region (Mumbai).

Step 3: Provide a VPC peering connection name and select VPC1 (requester).

Create A VPC Peering

Select ‘My account’ in the account section and ‘Another Region’ in the region section and select VPC2. Click ‘Create Peering Connection’.

Create A VPC Peering

Note: VPC peering connection can be set up between cross AWS account and cross region. In this demo, we are using the same AWS account but VPC’s are is cross region.

One success message will come, click ‘Close’.

Create A VPC Peering

Our new VPC peering connection successfully created.

Create A VPC Peering

Note: Current status is reflected as ‘Pending Acceptance’. In order to make this peering connection active, we need to navigate to the VPC2 region and accept this peering connection.

Step 4: Change the region to VPC2.

Create A VPC Peering

Step 5: Navigate to ‘Peering Connections’ and ‘Actions’. From the drop-down click ‘Accept Request’.

Create A VPC Peering

Create A VPC Peering

Click ‘Yes, Accept’.

Create A VPC Peering

One success message will be displayed, click ‘Close’.

Create A VPC Peering

Our VPC peering connection is now active and ready to use.

Create A VPC Peering

Create A VPC Peering

Next, let’s try to ping instance3 from instance2

Create A VPC Peering

Note: Still we are unable to connect to VPC2 from VPC1, though our VPC peering connection is active. This is due to the fact that VPC peering is not yet visible to the routers in VPC1 and VPC2. In order to use this VPC peering connection, we need to add subsequent route entry in both VPC.

VPC1 route table:

Create A VPC Peering

VPC2 route table:

Create A VPC Peering

Now we should be able to connect to instance3 from instance2

Create A VPC Peering

Cleanup: Navigate to ‘Peering Connections’ and from ‘Actions’ click ‘Delete VPC Peering Connections’.

Create A VPC Peering

Click ‘Yes, Delete’.

Create A VPC Peering

Hope you have enjoyed this blog post. In the next blog post, we are going to discuss security groups.

To get more details on VPC, please refer below AWS documentation

https://docs.aws.amazon.com/vpc/index.html

 

Leave a Reply

Close Menu