Comprehensive Guide to AWS VPC Peering: Configuring Multi-Region Connectivity

Muhammad Shahbaz - Aug 14 - - Dev Community

Image description

cloud network architecture with two regions: Region-1 and Region-2. In each region, there are two VPCs (Virtual Private Clouds) connected via an intra-region VPC peering connection. Additionally, each VPC in Region-1 is connected to VPC 3 in Region-2 using inter-region VPC peering connections. This setup allows for communication and resource sharing between VPCs within the same region and across different regions.
so we are going to implement this in the aws.so lets get start

Step 1: Create Two VPCs in N. Virginia Region
Login to AWS Management Console:

Navigate to the VPC Dashboard.
Create the First VPC:

VPC Name: VPC-A
CIDR Block: 10.0.0.0/16
Tenancy: Default (or Dedicated if required)
Create the Second VPC:

VPC Name: VPC-B
CIDR Block: 10.1.0.0/16
Tenancy: Default

Image description

Step 2: Create Subnets in Each VPC
For VPC-A:

Subnet 1 (AZ1):
Name: Subnet-A1
Availability Zone: us-east-1a (N. Virginia)
CIDR Block: 10.0.1.0/24

For VPC-B:

Subnet 1 (AZ1):
Name: Subnet-B1
Availability Zone: us-east-1a
CIDR Block: 10.1.1.0/24

Image description

Step 3: Create Internet Gateways and Route Tables for Each VPC
Create an Internet Gateway (IGW) for VPC-A:

Name: IGW-A
Attach it to VPC-A.
Create an Internet Gateway (IGW) for VPC-B:

Name: IGW-B
Attach it to VPC-B.
Update Route Tables:

For VPC-A:
Public Route Table: Create a route to 0.0.0.0/0 pointing to IGW-A.
Associate it with Subnet-vpcA
For VPC-B:
Public Route Table: Create a route to 0.0.0.0/0 pointing to IGW-B.
Associate it with Subnet-VpcB

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Step 4: Launch EC2 Instances in N. Virginia
Instance in VPC-A:

Name: Instance-vpcA
Subnet: Subnet-vpcA
Availability Zone: us-east-1a
Security Group: Create a security group allowing SSH (port 22) and ICMP (for ping).
Instance in VPC-B:

Name: Instance-vpcB
Subnet: Subnet-vpcB
Availability Zone: us-east-1b
Security Group: Create a security group allowing SSH (port 22) and ICMP (for ping).

Image description

Image description
another
Image description
instance name vpcB

Image description

Step 5: Create VPC Peering Between VPC-A and VPC-B in N. Virginia
Initiate VPC Peering Request:

search vpc
Go to the VPC Peering section.
Source VPC: VPC-A
Destination VPC: VPC-B
Accept the request from VPC-B.
Update Route Tables:

For VPC-A:
Update the route table associated with VPC-A to route traffic for 10.1.0.0/16 through the VPC Peering connection.
For VPC-B:
Update the route table associated with VPC-B to route traffic for 10.0.0.0/16 through the VPC Peering connection.

Image description

Image description

Image description

Image description

Image description

Step 6: Launch an EC2 Instance in Ohio Region
Create a VPC in Ohio:

VPC Name: VPC-C
CIDR Block: 10.2.0.0/16
Create subnets, an internet gateway, and route tables as needed.
Launch EC2 Instance in Ohio:

Name: Instance-vpcC
Subnet: Choose any subnet created in VPC-C.
Security Group: Create a security group allowing SSH (port 22) and ICMP (for ping)

Image description

Image description

Image description

Image description
Step 7: Establish VPC Peering Between VPC-C (Ohio) and VPCs in N. Virginia
Create VPC Peering Between VPC-A and VPC-C:

Initiate a peering request from VPC-A to VPC-C in the Ohio region.
Accept the request from VPC-C.
Create VPC Peering Between VPC-B and VPC-C:

Initiate a peering request from VPC-B to VPC-C in the Ohio region.
Accept the request from VPC-C.

Image description

Image description

Image description

Image description

accept from other region

Image description

Image description

so we have completed all the lab its time to check the connect
just open the ssh and pings private ips

Image description

Image description
its not ping each other because of we did not add route peering connect just follow these steps more
Update Route Tables:

For VPC-A:
Route traffic for 10.2.0.0/16 through the peering connection.
For VPC-B:
Route traffic for 10.2.0.0/16 through the peering connection.
For VPC-C:
Route traffic for 10.0.0.0/16 and 10.1.0.0/16 through the respective peering connections.

Image description

Image description

now its time to testing
Step 8: Testing Connectivity

SSH into Instance-vpcA (N. Virginia):

Attempt to ping and SSH into Instance-vpcA and Instance-vpcC ohio region.
Image description

Image description

SSH into Instance-vpcB (N. Virginia):

Attempt to ping and SSH into Instance-vpcC and Instance-vpcB.

Image description

Attempt to ping and SSH into Instance-VpcA and Instance-VpcB.

Image description

If all configurations are correct, the instances should be able to communicate across VPCs and regions.

. . . .
Terabox Video Player