Create VPC Peering
Tags: cloud, aws, networking, tutorial
Published: 2023-03-19 06:00:07

**What** : 
- AWS provided network connectivity between two VPC's.

**When** : 
- Multiple VPC's need to communicate or access each 
other's resources.

**Pros** : 
- Uses AWS backbone without traversing the Internet.

**Cons** : 
- Transitive peering is not supported.
  ex. if you have created peering between "VPC 1" and "VPC 2".one more peering between "VPC 1" to "VPC 3".Then "VPC 2" is not peered with "VPC 3".
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9iwcy6ynjmcnji1bxrtb.png)



**How**  : 
- VPC peering request made;accepter accepts requests (either within or across accounts).

A VPC peering connection is a networking connection between two VPC's 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 VPC's, or with a VPC in another AWS account. The VPC's can be in different regions (also known as an inter-region VPC peering connection). Data sent between VPC's in different regions is encrypted (traffic charges apply).

A VPC peering connection goes through various stages starting from when the request is initiated. At each stage, there may be actions that you can take, and at the end of its lifecycle, the VPC peering connection remains visible in the Amazon VPC console and API or command line output for a period of time.

![lifecycle of VPC peering](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gcchgtft4j654bcg2pyy.png)

**Setup: VPC Peering Connection**

1.  Create the VPCs.
To create a VPC peering connection, you need to have two VPCs that you want to connect. I am Creating one VPC with cidr range 10.0.0.0/16 and going to use default VPC.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hn9gq97n0gz3nwhdo645.png)
2. Navigate to the "peering connection" in the AWS Management Console.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8lbgznt2pohvptgiogmb.png)
3. click on "Create Peering Connection".Select the any of the above created vpc as a requester.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p6w0cpzi38tdhh49u524.png)
4. Select the accepter vpc.Accepter vpc can be in a different AWS account or in an different Region.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vfxm43rw84yub810mh40.png)
5. Click on create peering connection.Now you will be able to see one peering connection in the console.but the status will be shown as "pending acceptance".
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/awfzbzmisymahk0cfdbr.png)
6. Select the peering connection and click on the actions button.select the "Accept Request" option.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/58dml56gwvbjyf7nqnrk.png)
7. Now the status of peering connection will be available.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8cy6zzt29d2jcub2pdjb.png)
8. Only thing remaining is add an entry to route table.In my case i am adding an entry to "Test-VPC" route table.created new route with the cidr range of default vpc and used the created peering connection id as a target.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5tq94pumoq8xbx98y3xe.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/12cdkgix4xkr31wnwqna.png)
9. Now change the route table of accepter vpc.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aah27vhu6nb4ljoobqsx.png)

We have successfully created vpc peering between "Test Vpc" and "default VPC".

**Pros:**

**Simplicity**: VPC peering provides a simple way to connect VPCs, without requiring any external resources like VPNs or dedicated connections.
**Cost-effectiveness**: Since VPC peering relies on the cloud provider's internal network, it is usually more cost-effective than using external connections.
**Security**: VPC peering allows you to keep traffic between VPCs within the provider's network, which can be more secure than using external connections.
**Low Latency**: Since VPC peering uses the provider's internal network, it generally provides low latency connections between VPCs.

**Cons:**

**Limited scope**: VPC peering only works within a single cloud provider's infrastructure and can't connect VPCs in different cloud providers.
**Bandwidth limitations**: VPC peering has limits on the amount of traffic that can be transferred between VPCs, and exceeding these limits can result in degraded performance.
**No transitive peering**: VPC peering only supports direct connections between VPCs, so if you need to connect more than two VPCs, you'll need to set up multiple peering connections.
**Potential for overlapping IP addresses**: VPCs that are peered together cannot have overlapping IP address ranges, so this needs to be carefully managed to avoid conflicts.

**Conclusion:**

In this blog, we have discussed the steps required to create a VPC peering connection between two VPC's in the same region. VPC peering is a powerful feature that enables you to connect two or more VPC's within the same or different regions or accounts. It can be used to share resources between VPC's, facilitate communication between applications in different VPC's, and improve availability and fault tolerance of your infrastructure.