Bird
Raised Fist0
AWScloud~10 mins

VPC peering concept in AWS - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a VPC peering connection between two VPCs.

AWS
resource "aws_vpc_peering_connection" "peer" {
  vpc_id        = "[1]"
  peer_vpc_id   = "vpc-0a1b2c3d4e5f6g7h8"
  peer_region   = "us-west-2"
}
Drag options to blanks, or click blank then click option'
Avpc-111aaa22
Bvpc-123abc45
Cvpc-0a1b2c3d4e5f6g7h8
Dvpc-987zyx65
Attempts:
3 left
💡 Hint
Common Mistakes
Using the peer VPC ID for the vpc_id field.
Mixing up VPC IDs between requester and peer.
2fill in blank
medium

Complete the code to allow DNS resolution over the VPC peering connection.

AWS
resource "aws_vpc_peering_connection_options" "peer_options" {
  vpc_peering_connection_id = aws_vpc_peering_connection.peer.id
  requester {
    [1] = true
  }
  accepter {
    allow_dns_resolution_from_remote_vpc = true
  }
}
Drag options to blanks, or click blank then click option'
Aallow_dns_resolution_from_remote_vpc
Ballow_classic_link_to_remote_vpc
Callow_vpc_to_remote_classic_link
Dallow_remote_vpc_dns_resolution
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect attribute names that do not exist.
Confusing DNS resolution with ClassicLink settings.
3fill in blank
hard

Fix the error in the VPC peering connection resource by completing the missing field.

AWS
resource "aws_vpc_peering_connection" "peer" {
  vpc_id      = "vpc-123abc45"
  peer_vpc_id = "[1]"
  peer_owner_id = "123456789012"
}
Drag options to blanks, or click blank then click option'
Avpc-123abc45
Bvpc-999zzz88
Cvpc-0a1b2c3d4e5f6g7h8
Dvpc-555bbb33
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same VPC ID for both vpc_id and peer_vpc_id.
Leaving out the peer_vpc_id field.
4fill in blank
hard

Fill both blanks to configure route tables to allow traffic over the VPC peering connection.

AWS
resource "aws_route" "peer_route" {
  route_table_id         = "[1]"
  destination_cidr_block = "[2]"
  vpc_peering_connection_id = aws_vpc_peering_connection.peer.id
}
Drag options to blanks, or click blank then click option'
Artb-0a1b2c3d4e5f6g7h8
B10.0.0.0/16
Crtb-123abc45
D192.168.0.0/16
Attempts:
3 left
💡 Hint
Common Mistakes
Using the peer VPC's route table ID instead of the local VPC's.
Mixing up CIDR blocks between local and peer VPCs.
5fill in blank
hard

Fill all three blanks to define a VPC peering connection with tags and accept the peering request.

AWS
resource "aws_vpc_peering_connection" "peer" {
  vpc_id        = "[1]"
  peer_vpc_id   = "[2]"
  auto_accept   = [3]

  tags = {
    Name = "MyVPCPeering"
  }
}
Drag options to blanks, or click blank then click option'
Avpc-abc12345
Bvpc-def67890
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same VPC ID for both vpc_id and peer_vpc_id.
Setting auto_accept to false when automatic acceptance is desired.

Practice

(1/5)
1. What is the main purpose of VPC peering in AWS?
easy
A. To connect two private networks securely within AWS
B. To provide public internet access to a VPC
C. To create a backup of a VPC in another region
D. To launch virtual machines automatically

Solution

  1. Step 1: Understand VPC peering concept

    VPC peering connects two private networks (VPCs) securely inside AWS without using the public internet.
  2. Step 2: Compare options

    Only To connect two private networks securely within AWS describes secure connection of private networks. Other options describe unrelated AWS features.
  3. Final Answer:

    To connect two private networks securely within AWS -> Option A
  4. Quick Check:

    VPC peering = secure private network connection [OK]
Hint: VPC peering links private networks, not public access [OK]
Common Mistakes:
  • Confusing VPC peering with internet gateway
  • Thinking VPC peering creates backups
  • Assuming it launches virtual machines
2. Which of the following is the correct way to create a VPC peering connection using AWS CLI?
easy
A. aws ec2 create-route-table --vpc-id vpc-123abc
B. aws ec2 create-vpc-peering-connection --vpc-id vpc-123abc --peer-vpc-id vpc-456def
C. aws ec2 create-subnet --vpc-id vpc-123abc --cidr-block 10.0.0.0/24
D. aws ec2 create-internet-gateway --vpc-id vpc-123abc

Solution

  1. Step 1: Identify the correct AWS CLI command for VPC peering

    The command to create a VPC peering connection is create-vpc-peering-connection with source and peer VPC IDs.
  2. Step 2: Check options

    aws ec2 create-vpc-peering-connection --vpc-id vpc-123abc --peer-vpc-id vpc-456def uses the correct command and parameters. Other options create unrelated resources like internet gateway, subnet, or route table.
  3. Final Answer:

    aws ec2 create-vpc-peering-connection --vpc-id vpc-123abc --peer-vpc-id vpc-456def -> Option B
  4. Quick Check:

    VPC peering CLI = create-vpc-peering-connection [OK]
Hint: Look for 'create-vpc-peering-connection' command [OK]
Common Mistakes:
  • Using internet gateway or subnet commands instead
  • Confusing route table creation with peering
  • Missing peer VPC ID parameter
3. After establishing a VPC peering connection between VPC A and VPC B, which step is necessary to enable communication between instances in both VPCs?
medium
A. Attach a NAT gateway to both VPCs
B. Create an internet gateway in both VPCs
C. Enable public IP addresses on all instances
D. Update route tables in both VPCs to include routes to each other's CIDR blocks

Solution

  1. Step 1: Understand VPC peering communication requirements

    VPC peering connects networks but does not automatically update routing. You must add routes to route tables for traffic to flow.
  2. Step 2: Analyze options

    Only Update route tables in both VPCs to include routes to each other's CIDR blocks correctly describes updating route tables with routes to the peer VPC's CIDR block. Other options relate to internet or NAT, not peering.
  3. Final Answer:

    Update route tables in both VPCs to include routes to each other's CIDR blocks -> Option D
  4. Quick Check:

    Route tables must include peer CIDR for communication [OK]
Hint: Always update route tables after peering [OK]
Common Mistakes:
  • Assuming internet gateway is needed for peering
  • Thinking public IPs are required
  • Confusing NAT gateway with peering setup
4. You created a VPC peering connection but instances in VPC A cannot reach instances in VPC B. What is the most likely cause?
medium
A. Instances need public IP addresses to communicate over peering
B. The VPC peering connection is automatically rejected after creation
C. Route tables in VPC A or VPC B do not have routes to the peer VPC's CIDR block
D. Security groups do not allow internet traffic

Solution

  1. Step 1: Check common VPC peering issues

    Communication fails often because route tables lack routes to the peer VPC's CIDR block.
  2. Step 2: Evaluate other options

    The VPC peering connection is automatically rejected after creation is false; peering is not auto-rejected. Instances need public IP addresses to communicate over peering is wrong; public IPs are not needed. Security groups do not allow internet traffic is unrelated to peering communication.
  3. Final Answer:

    Route tables in VPC A or VPC B do not have routes to the peer VPC's CIDR block -> Option C
  4. Quick Check:

    Missing routes cause peering communication failure [OK]
Hint: Check route tables first when peering fails [OK]
Common Mistakes:
  • Assuming peering rejects automatically
  • Thinking public IPs are required for peering
  • Confusing security group rules with internet traffic
5. You have two VPCs in different AWS regions and want to connect them using VPC peering. What is the correct approach?
hard
A. Create an inter-region VPC peering connection and update route tables accordingly
B. Create a standard VPC peering connection; region does not matter
C. Use an internet gateway to connect the two VPCs
D. Launch VPN instances in both VPCs and connect them manually

Solution

  1. Step 1: Understand VPC peering across regions

    A special inter-region VPC peering connection is required to connect VPCs in different AWS regions.
  2. Step 2: Analyze options

    Create an inter-region VPC peering connection and update route tables accordingly correctly states creating an inter-region peering and updating routes. Create a standard VPC peering connection; region does not matter is wrong because standard peering is regional. Use an internet gateway to connect the two VPCs and D describe unrelated or complex alternatives.
  3. Final Answer:

    Create an inter-region VPC peering connection and update route tables accordingly -> Option A
  4. Quick Check:

    Inter-region peering requires special connection and routing [OK]
Hint: Use inter-region peering for different AWS regions [OK]
Common Mistakes:
  • Trying standard peering across regions
  • Using internet gateway for private VPC connection
  • Ignoring route table updates after peering