Bird
Raised Fist0
AWScloud~10 mins

Route tables configuration 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 route table in AWS using Terraform.

AWS
resource "aws_route_table" "example" {
  vpc_id = [1]
}
Drag options to blanks, or click blank then click option'
Aaws_vpc.main.id
Baws_subnet.main.id
Caws_internet_gateway.main.id
Daws_route_table.main.id
Attempts:
3 left
💡 Hint
Common Mistakes
Using subnet ID instead of VPC ID
Referencing the internet gateway ID directly
Using the route table's own ID before creation
2fill in blank
medium

Complete the code to add a route to the route table that directs all traffic to the internet gateway.

AWS
resource "aws_route" "internet_access" {
  route_table_id         = aws_route_table.example.id
  destination_cidr_block = [1]
  gateway_id             = aws_internet_gateway.main.id
}
Drag options to blanks, or click blank then click option'
A192.168.1.0/24
B0.0.0.0/0
C10.0.0.0/16
D172.16.0.0/12
Attempts:
3 left
💡 Hint
Common Mistakes
Using a private subnet CIDR block instead of all traffic
Using a subnet CIDR block that limits traffic
Confusing the destination CIDR with the gateway ID
3fill in blank
hard

Fix the error in the route association code by completing the blank.

AWS
resource "aws_route_table_association" "example_assoc" {
  subnet_id      = [1]
  route_table_id = aws_route_table.example.id
}
Drag options to blanks, or click blank then click option'
Aaws_subnet.public.id
Baws_route_table.example.id
Caws_internet_gateway.main.id
Daws_vpc.main.id
Attempts:
3 left
💡 Hint
Common Mistakes
Using the route table ID as subnet ID
Using the internet gateway ID instead of subnet ID
Using the VPC ID instead of subnet ID
4fill in blank
hard

Fill both blanks to create a route that sends traffic to a NAT gateway for private subnet internet access.

AWS
resource "aws_route" "private_nat" {
  route_table_id         = aws_route_table.private.id
  destination_cidr_block = [1]
  [2]             = aws_nat_gateway.main.id
}
Drag options to blanks, or click blank then click option'
A10.0.0.0/16
Bnat_gateway_id
C0.0.0.0/0
Dgateway_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using gateway_id instead of nat_gateway_id
Using a private subnet CIDR block instead of all traffic
Mixing up NAT gateway and internet gateway attributes
5fill in blank
hard

Fill all three blanks to define a route table with a route and associate it with a subnet.

AWS
resource "aws_route_table" "example" {
  vpc_id = [1]
}

resource "aws_route" "example_route" {
  route_table_id         = aws_route_table.example.id
  destination_cidr_block = [2]
  gateway_id             = aws_internet_gateway.main.id
}

resource "aws_route_table_association" "example_assoc" {
  subnet_id      = [3]
  route_table_id = aws_route_table.example.id
}
Drag options to blanks, or click blank then click option'
Aaws_vpc.main.id
B0.0.0.0/0
Caws_subnet.public.id
Daws_nat_gateway.main.id
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up subnet and VPC IDs
Using NAT gateway ID instead of internet gateway ID
Using private subnet ID instead of public subnet ID

Practice

(1/5)
1. What is the main purpose of a route table in AWS networking?
easy
A. To manage user permissions
B. To store user data securely
C. To direct network traffic between subnets and gateways
D. To monitor server health

Solution

  1. Step 1: Understand the role of route tables

    Route tables control how network traffic moves inside a cloud network by defining paths.
  2. Step 2: Identify what route tables connect

    They connect subnets to gateways or other networks, enabling communication.
  3. Final Answer:

    To direct network traffic between subnets and gateways -> Option C
  4. Quick Check:

    Route tables = traffic direction [OK]
Hint: Route tables guide traffic flow inside the cloud [OK]
Common Mistakes:
  • Confusing route tables with security groups
  • Thinking route tables store data
  • Mixing route tables with monitoring tools
2. Which of the following is the correct way to associate a route table with a subnet in AWS CLI?
easy
A. aws ec2 create-route-table --subnet-id subnet-12345 --route-table-id rtb-67890
B. aws ec2 associate-route-table --subnet-id subnet-12345 --route-table-id rtb-67890
C. aws ec2 attach-route-table --subnet subnet-12345 --table rtb-67890
D. aws ec2 link-route-table --subnet subnet-12345 --route-table rtb-67890

Solution

  1. Step 1: Identify the correct AWS CLI command for association

    The command to associate a route table with a subnet is 'associate-route-table'.
  2. Step 2: Check the correct syntax and parameters

    The correct syntax uses '--subnet-id' and '--route-table-id' flags with IDs.
  3. Final Answer:

    aws ec2 associate-route-table --subnet-id subnet-12345 --route-table-id rtb-67890 -> Option B
  4. Quick Check:

    Associate route table = associate-route-table command [OK]
Hint: Use 'associate-route-table' with subnet and route table IDs [OK]
Common Mistakes:
  • Using 'create-route-table' instead of 'associate-route-table'
  • Wrong parameter names like '--subnet' instead of '--subnet-id'
  • Using non-existent commands like 'attach-route-table'
3. Given a route table with the following routes:
Destination: 0.0.0.0/0, Target: igw-12345
Destination: 10.0.1.0/24, Target: local
What happens when an instance in subnet 10.0.1.0/24 tries to reach 8.8.8.8?
medium
A. Traffic is sent to the internet gateway (igw-12345)
B. Traffic is blocked because no route exists
C. Traffic is sent to the local subnet only
D. Traffic is sent to a NAT gateway automatically

Solution

  1. Step 1: Analyze the route for 0.0.0.0/0

    This route sends all traffic not matching other routes to the internet gateway (igw-12345).
  2. Step 2: Determine route for 8.8.8.8

    Since 8.8.8.8 is outside the local subnet, it matches the 0.0.0.0/0 route and goes to the internet gateway.
  3. Final Answer:

    Traffic is sent to the internet gateway (igw-12345) -> Option A
  4. Quick Check:

    Default route sends traffic to internet gateway [OK]
Hint: Default 0.0.0.0/0 route sends traffic outside subnet [OK]
Common Mistakes:
  • Assuming traffic is blocked without explicit deny
  • Confusing local route with internet access
  • Thinking NAT gateway is used without configuration
4. You created a route table and associated it with a subnet, but instances in that subnet cannot access the internet. What is the most likely mistake?
medium
A. The route table lacks a route to an internet gateway
B. The subnet is not associated with any route table
C. The route table has a route to a NAT gateway instead of an internet gateway
D. The instances have no security group attached

Solution

  1. Step 1: Check route table routes for internet access

    Internet access requires a route to an internet gateway (igw) for 0.0.0.0/0.
  2. Step 2: Identify missing or incorrect routes

    If the route to the internet gateway is missing, instances cannot reach the internet despite association.
  3. Final Answer:

    The route table lacks a route to an internet gateway -> Option A
  4. Quick Check:

    Internet needs 0.0.0.0/0 route to igw [OK]
Hint: Check for 0.0.0.0/0 route to internet gateway [OK]
Common Mistakes:
  • Assuming subnet association alone grants internet access
  • Confusing NAT gateway with internet gateway routes
  • Ignoring security group rules as cause
5. You have two subnets: Subnet A (10.0.1.0/24) and Subnet B (10.0.2.0/24). You want instances in Subnet A to access the internet via a NAT gateway in Subnet B, but Subnet B should not have direct internet access. How should you configure the route tables?
hard
A. Associate Subnet A's route table with 0.0.0.0/0 to the NAT gateway; Subnet B's route table with no route to internet gateway
B. Associate Subnet A's route table with 0.0.0.0/0 to the internet gateway; Subnet B's route table with 0.0.0.0/0 to the NAT gateway
C. Associate both subnets' route tables with 0.0.0.0/0 to the internet gateway
D. Associate Subnet A's route table with a route 0.0.0.0/0 to the NAT gateway; Subnet B's route table with 0.0.0.0/0 to the internet gateway

Solution

  1. Step 1: Understand NAT gateway purpose

    NAT gateway allows instances in private subnet (Subnet A) to access internet outbound.
  2. Step 2: Configure Subnet B's route table (NAT subnet)

    Subnet B must have 0.0.0.0/0 to internet gateway so NAT can reach internet. Direct access for instances in B can be restricted via security groups.
  3. Step 3: Configure Subnet A's route table

    Subnet A has 0.0.0.0/0 to NAT gateway.
  4. Final Answer:

    Associate Subnet A's route table with a route 0.0.0.0/0 to the NAT gateway; Subnet B's route table with 0.0.0.0/0 to the internet gateway -> Option D
  5. Quick Check:

    Private to NAT; NAT subnet to igw [OK]
Hint: Private subnet (A) routes to NAT; NAT subnet (B) routes to igw [OK]
Common Mistakes:
  • Omitting igw route in NAT subnet (B), breaking NAT functionality
  • Routing private subnet (A) directly to igw
  • Confusing NAT gateway and internet gateway roles