skip to content

Two VPCs in the same AWS Region have a VPC peering connection, but instances in one still cannot reach instances in the other. What has to be in place before a peering connection actually carries traffic?

level: juniorimportance: should knowfreq 60%

answer

  1. three parts, not one
  2. handshake, then routing, then firewall
  3. the reply needs a route too
  4. peer security group by ID, same Region
  5. addresses must not collide

basics

~20 s

A VPC peering connection carries traffic only after the peer accepts the request, both VPCs add route-table entries sending the other's CIDR to the peering connection, and security groups and NACLs on both sides allow the traffic.

solid answer

~50 s

Peering is a three-part setup and people usually stop after the first part. First the handshake: the requester creates the connection and the accepter — often a different account — has to accept it. Second, routing: in **both** VPCs you add a route whose destination is the other VPC's CIDR and whose target is the peering connection (`pcx-…`). Adding it on one side only gives you a request that leaves and a reply with no way back, which looks like a timeout. Third, the firewalls: security groups and network ACLs must permit the traffic; peering does not bypass them. Two constraints sit underneath all of it — the VPCs' CIDR blocks must not overlap, or AWS refuses to create the connection, and if you want the peer's private DNS names to resolve to private IPs you have to enable DNS resolution on the peering connection on each side.

code

bash · 15 lines
bash
# 1. request, then accept (the accepter is often another account)
aws ec2 create-vpc-peering-connection \
  --vpc-id vpc-0aaa1111 --peer-vpc-id vpc-0bbb2222

aws ec2 accept-vpc-peering-connection \
  --vpc-peering-connection-id pcx-0123456789abcdef0

# 2. a route in EACH VPC, pointing at the peering connection
aws ec2 create-route --route-table-id rtb-0aaa1111 \
  --destination-cidr-block 10.1.0.0/16 \
  --vpc-peering-connection-id pcx-0123456789abcdef0

aws ec2 create-route --route-table-id rtb-0bbb2222 \
  --destination-cidr-block 10.0.0.0/16 \
  --vpc-peering-connection-id pcx-0123456789abcdef0

go deeper

for a junior

Be able to list the three things a peering connection needs before traffic flows: accept the request, add routes in both VPCs' route tables, and open the security groups. Say "both sides" out loud when you get to routing.

for a middle

Explain the failure signature of each missing piece — a one-sided route produces a timeout, a missing security group rule produces a REJECT in flow logs — and note the non-overlapping-CIDR requirement and the peer security-group reference within a Region.

for a senior

Show how you triage this in production rather than guessing: check the connection state, confirm the route exists in the route table actually associated with the instance's subnet, then use Reachability Analyzer or flow logs to name the dropping hop.

for a principal

Own the policy rather than the wiring: decide whether teams may create peering connections at all, or whether every VPC-to-VPC path goes through a shared Transit Gateway the platform team controls, and how address space is allocated so overlaps never happen.

## What a peering connection actually is A VPC peering connection is a networking link between exactly two VPCs, created inside the AWS network fabric rather than over the internet. There is no appliance, no gateway object in the data path, no bandwidth tier to pick and no hourly charge for the connection itself — you pay only for data transfer. Because there is no device, there is also nothing that "turns it on": the connection is a permission plus a routing target, and until you use that target nothing changes. ## Step 1 — request and accept One side creates the request (`CreateVpcPeeringConnection`), naming its own VPC and the peer VPC, which may be in another account or another Region. The connection sits in `pending-acceptance` until the owner of the other VPC accepts it. That acceptance is the authorization boundary: nobody can wire their VPC into yours unilaterally. In a single account you can request and accept in the same breath, which is why single-account examples make people think acceptance is the whole job. The request fails outright if the two VPCs' CIDR blocks overlap — including any secondary CIDRs. There is no NAT in peering, so overlapping address space has no answer; the fix is renumbering or a different pattern entirely, such as exposing a single service privately instead of joining whole networks. ## Step 2 — routes on both sides An accepted peering connection moves no packets by itself. In VPC A's route tables you add: ``` destination 10.1.0.0/16 -> target pcx-0123456789abcdef0 ``` and in VPC B's route tables the mirror image pointing at A's CIDR. "Both sides" is the part that trips people up, and its failure mode is distinctive: the SYN reaches the peer instance, the peer's reply hits a route table with no entry for the source range, and the caller sees a hang rather than a refusal. Remember also that a route table is attached to specific subnets — if only the subnets in one AZ use the route table you edited, only instances there can talk. ## Step 3 — security groups and NACLs Peered traffic is ordinary VPC traffic and is filtered normally. The inbound rule on the destination instance's security group has to allow the source range or, better, the source security group. Inside a single Region — including across accounts — a security group rule can reference a security group **in the peer VPC by ID**, which keeps you out of CIDR bookkeeping. Inter-Region peering does not support that reference, so there you fall back to CIDR-based rules. ## The DNS detail By default an instance in A resolving a private hostname belonging to B gets the public address, or nothing. Each side of the peering connection has a DNS-resolution option (`AllowDnsResolutionFromRemoteVpc`) that, when enabled, lets queries from the peer resolve to private IPs. The VPC itself must also have DNS support and DNS hostnames enabled. ## What peering deliberately does not do - It is not transitive: peering A–B and B–C does not let A reach C. - It does not give you the peer's internet path. You cannot route through a peering connection to reach the peer VPC's internet gateway, NAT gateway, VPN or Direct Connect connection, or its gateway endpoints. AWS calls this the edge-to-edge routing restriction. - It is not a trust boundary you can forget about: once routes exist, reachability is governed only by your security groups and NACLs. ## Checking it quickly The fastest triage order mirrors the setup order — is the connection `active`, does each side have a route for the other's CIDR in the route table associated with the right subnets, and do the security groups allow the port. VPC Reachability Analyzer will walk that path for you and name the hop that drops the packet, and flow logs will show `REJECT` when a security group or NACL is the culprit. ## What interviewers listen for They want to hear "routes on both sides" unprompted, and they want you to treat the accepted connection as necessary but not sufficient. Naming the overlapping-CIDR constraint and the peer-security-group reference marks you as someone who has actually built one.

  • What exactly goes wrong if only one of the two VPCs has the route?
    The outbound packet is delivered, but the peer's route table has no entry for the source CIDR, so the reply is dropped in the peer VPC. The caller sees a connection timeout rather than a refusal, which is why one-sided routing is usually misdiagnosed as a security-group problem.
  • Can a security group rule reference a security group in the peered VPC instead of a CIDR range?
    Yes for peering within a single Region, including cross-account: an inbound rule can name the peer's security group ID directly, so the allow-list follows instances rather than address ranges. Inter-Region peering does not support cross-VPC security group references, so there you must use CIDR-based rules.
  • Instances in the peer VPC resolve to public IPs instead of private ones. What did you miss?
    The peering connection's DNS resolution option. Each side has a setting that allows DNS queries from the peer VPC to resolve private hostnames to private IPs; without it, Route 53 returns the public address. The VPCs also need DNS support and DNS hostnames enabled.

saying these in an interview costs you the question

  • Accepting the peering request is enough; routing happens automatically
  • One route table entry covers both directions
  • Peered VPCs can have overlapping CIDRs because AWS NATs them
  • Security groups do not apply to traffic arriving over peering
  • Peering requires an internet gateway or public IP addresses

context