Review destination ranges for VPC peering routes

Limit VPC peering route destinations to the addresses that need communication in the peer VPC.

Description

Route only the peer VPC addresses you need over the peering connection. 0.0.0.0/0 or ::/0 also sends traffic there when no more specific route matches.

Potential impact

Peering cannot provide transit to another VPC or share the peer’s internet gateway or NAT. Traffic sent there by mistake can lose its route to the destination.

Remediation

Check that peering is active. On both sides, verify subnet associations, destination and return routes, and security group rules. Test the intended connections in both directions and confirm that other destinations still use the correct routes.

Examples

The second excerpt uses a different route table and limits the destination to the CIDR of vpc2. To change an existing subnet’s routing, update its active table or associate the new one. Supply the referenced VPCs and peering connection.

Before

hcl
resource "aws_route_table" "public_route_table" {
  vpc_id = aws_vpc.vpc1.id

  route {
    cidr_block                = "0.0.0.0/0"
    vpc_peering_connection_id = aws_vpc_peering_connection.my_peering.id
  }
}

After

hcl
resource "aws_route_table" "private_route_table" {
  vpc_id = aws_vpc.vpc1.id

  route {
    cidr_block                = aws_vpc.vpc2.cidr_block
    vpc_peering_connection_id = aws_vpc_peering_connection.my_peering.id
  }
}

References