AWS VPC Peering
Use AWS VPC peering to establish private connectivity between VPCs through the AWS network.
What Is VPC Peering?
A VPC peering connection is a private network connection between two VPCs. Instances in each VPC can communicate using private IPv4 or IPv6 addresses, traffic stays within the AWS network, and no internet gateway, NAT device, VPN connection, or public IP address is required.
VPC peering supports VPCs in the same AWS Region or different Regions. It can also connect VPCs owned by the same AWS account or by different AWS accounts. A peering connection is not a transitive connection: if VPC A is peered with VPC B and VPC C, VPC B cannot use VPC A to reach VPC C.
Common Use Cases
- Connect applications and databases in separate VPCs.
- Share a centralized service, such as DNS or monitoring, with other VPCs.
- Connect VPCs owned by different teams or business units.
- Move traffic between VPCs in different AWS Regions.
- Support VPC migrations by maintaining connectivity during a transition.
CIDR Requirements
The IPv4 CIDR blocks of the two VPCs must not overlap. The same rule generally applies to IPv6 CIDR blocks, and AWS will reject a peering request when it detects incompatible or overlapping routing configurations.
Before creating the connection, plan the CIDR ranges for all VPCs that may need to communicate. Overlapping ranges can make routes ambiguous and prevent a peering connection from working reliably.
How VPC Peering Works
Creating a peering connection requires the following steps:
- Send a peering request from the requester VPC.
- Accept the request from the accepter VPC.
- Add a route in each VPC’s route table.
- Update security groups, network ACLs, and route-table configurations.
- Test private connectivity from both sides.
The route in VPC A should target VPC B’s CIDR block through the peering connection. The route in VPC B should target VPC A’s CIDR block through the same connection.
The following example adds routes in the AWS CLI:
1 | # Route traffic for VPC B's CIDR through the peering connection |
Both route tables must be used by the relevant subnets. Adding the peering route to only one route table will leave that subnet unable to send traffic.
Example Architecture
1 | VPC A: 10.10.0.0/16 VPC B: 10.20.0.0/16 |
Cross-Account Peering
For cross-account peering, the requester sends the request and the owner of the accepter VPC accepts it. The accepter account is not required to share IAM permissions beyond the permission needed to accept and manage the peering connection.
After the connection is active, both accounts must add routes and update their security rules. Resource-based or identity-based IAM policies do not replace network security controls; they only control which AWS API operations users and roles can perform.
DNS Resolution
By default, private DNS hostnames of instances in a VPC are not resolved to private IP addresses for instances in the peered VPC. You can enable the following DNS options on each side as needed:
enableDnsHostnamesfor instances to receive DNS hostnames.enableDnsSupportfor DNS resolution within the VPC.- Peering connection DNS options to resolve public or private hostnames across the peering connection.
DNS behavior varies when Route 53 Resolver endpoints or private hosted zones are involved. Verify DNS resolution with a private IP address and a private DNS name before assuming the network path is correct.
Security Configuration
A VPC peering connection does not add traffic encryption beyond the normal AWS network. It does not override security group or network ACL rules.
For least-privilege access:
- Add only the required source CIDR in security group rules.
- Prefer security groups as sources when the peering relationship and AWS configuration support it.
- Restrict network ACL rules to the required protocols and ports.
- Avoid opening an entire VPC CIDR block if only one application tier needs access.
- Keep routes intentionally scoped to the destination networks.
VPC Peering Limitations
VPC peering has no transitive routing. For example, traffic cannot move from VPC B to VPC C through VPC A merely because both VPCs are peered with VPC A.
Other common limitations include:
- VPC CIDR blocks cannot overlap.
- Peered VPCs cannot share some AWS service endpoints unless the endpoint and service configuration explicitly support the route.
- A single VPC cannot have two peering connections that cause conflicting routes for overlapping destination CIDRs.
- Edge-to-edge routing is not supported for routes through an internet gateway, NAT gateway, VPN connection, Direct Connect gateway, or transit gateway in the other VPC.
- Every resource, DNS setting, route, and security rule must be checked when troubleshooting.
Peering Versus AWS Transit Gateway
VPC peering is appropriate for a small number of VPC-to-VPC connections. It provides a direct private path and can be simpler to manage for isolated workloads.
AWS Transit Gateway is usually better when many VPCs need to communicate or when on-premises networks and several VPCs share a centrally managed routing hub. Transit Gateway supports a transitive, hub-and-spoke design, while VPC peering creates direct connections between pairs of VPCs.
| Requirement | VPC Peering | AWS Transit Gateway |
|---|---|---|
| Direct private connection | Yes | Yes, through a transit hub |
| Transitive routing | No | Yes |
| Suitable for many VPCs | Becomes complex | Generally easier |
| Central routing policy | No | Yes |
| Cross-Region support | Yes | Yes |
Troubleshooting
If connectivity fails, work through these checks:
- Confirm the peering connection is in the
activestate. - Confirm both route tables contain the correct destination and peering connection ID.
- Confirm the route-table is associated with the source and destination subnets.
- Confirm security groups allow traffic from the remote private CIDR or security group.
- Confirm network ACLs allow inbound and outbound traffic.
- Confirm the destination service is listening on the expected port.
- Verify that no overlapping CIDR block or competing route exists.
- For cross-Region peering, confirm Region and resource settings.
Useful AWS CLI checks include:
1 | # Check the peering connection |
AWS Reachability Analyzer can also trace the network path between a source and destination network interface. For a quick connectivity test, use tools such as curl, telnet, or nc from a source instance.