Bird
Raised Fist0
AWScloud~10 mins

Internet Gateway for public access 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 an Internet Gateway resource in AWS CloudFormation.

AWS
Resources:
  MyInternetGateway:
    Type: [1]
Drag options to blanks, or click blank then click option'
AAWS::EC2::InternetGateway
BAWS::EC2::Subnet
CAWS::S3::Bucket
DAWS::EC2::VPC
Attempts:
3 left
💡 Hint
Common Mistakes
Using VPC or Subnet resource types instead of Internet Gateway.
Confusing S3 bucket resource with networking resources.
2fill in blank
medium

Complete the code to attach the Internet Gateway to a VPC.

AWS
Resources:
  AttachGateway:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: [1]
      InternetGatewayId: !Ref MyInternetGateway
Drag options to blanks, or click blank then click option'
AMySubnet
BMySecurityGroup
CMyRouteTable
DMyVPC
Attempts:
3 left
💡 Hint
Common Mistakes
Using Subnet or Security Group IDs instead of VPC ID.
Confusing Route Table with VPC.
3fill in blank
hard

Fix the error in the route table to enable public internet access through the Internet Gateway.

AWS
Resources:
  PublicRoute:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref PublicRouteTable
      DestinationCidrBlock: [1]
      GatewayId: !Ref MyInternetGateway
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
D255.255.255.0
Attempts:
3 left
💡 Hint
Common Mistakes
Using private IP ranges instead of 0.0.0.0/0.
Using subnet masks instead of CIDR notation.
4fill in blank
hard

Fill both blanks to define a public subnet with a route to the Internet Gateway.

AWS
Resources:
  PublicSubnet:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: [1]
      CidrBlock: 10.0.1.0/24
  PublicRoute:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref PublicRouteTable
      DestinationCidrBlock: [2]
      GatewayId: !Ref MyInternetGateway
Drag options to blanks, or click blank then click option'
AMyVPC
BMySubnet
C0.0.0.0/0
D10.0.0.0/16
Attempts:
3 left
💡 Hint
Common Mistakes
Using subnet ID instead of VPC ID for subnet property.
Using private CIDR blocks for route destination.
5fill in blank
hard

Fill all three blanks to create an Internet Gateway, attach it to a VPC, and add a route for public access.

AWS
Resources:
  InternetGateway:
    Type: [1]
  AttachGateway:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: [2]
      InternetGatewayId: !Ref InternetGateway
  PublicRoute:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref PublicRouteTable
      DestinationCidrBlock: [3]
      GatewayId: !Ref InternetGateway
Drag options to blanks, or click blank then click option'
AAWS::EC2::InternetGateway
BMyVPC
C0.0.0.0/0
DAWS::EC2::Subnet
Attempts:
3 left
💡 Hint
Common Mistakes
Using subnet resource type instead of Internet Gateway.
Using subnet ID instead of VPC ID for attachment.
Using private CIDR blocks instead of 0.0.0.0/0 for route.

Practice

(1/5)
1. What is the main purpose of an Internet Gateway in AWS?
easy
A. To allow communication between a VPC and the internet
B. To store data securely in the cloud
C. To manage user permissions in AWS
D. To create private subnets within a VPC

Solution

  1. Step 1: Understand the role of an Internet Gateway

    An Internet Gateway is a component that connects a Virtual Private Cloud (VPC) to the internet, enabling resources in the VPC to access or be accessed from the internet.
  2. Step 2: Identify the correct purpose

    Among the options, only allowing communication between a VPC and the internet matches the Internet Gateway's function.
  3. Final Answer:

    To allow communication between a VPC and the internet -> Option A
  4. Quick Check:

    Internet Gateway = Connects VPC to internet [OK]
Hint: Internet Gateway connects VPC to internet, not storage or permissions [OK]
Common Mistakes:
  • Confusing Internet Gateway with storage services
  • Thinking it manages user permissions
  • Assuming it creates private subnets
2. Which AWS resource must an Internet Gateway be attached to for it to provide internet access?
easy
A. An EC2 instance
B. A Virtual Private Cloud (VPC)
C. An S3 bucket
D. A Security Group

Solution

  1. Step 1: Identify the attachment requirement of an Internet Gateway

    An Internet Gateway must be attached to a VPC to enable internet access for resources inside that VPC.
  2. Step 2: Match the correct AWS resource

    Among the options, only a VPC is the correct resource to attach an Internet Gateway to.
  3. Final Answer:

    A Virtual Private Cloud (VPC) -> Option B
  4. Quick Check:

    Internet Gateway attaches to VPC [OK]
Hint: Internet Gateway attaches only to VPC, not instances or buckets [OK]
Common Mistakes:
  • Trying to attach Internet Gateway directly to EC2
  • Confusing with storage like S3 buckets
  • Thinking it attaches to Security Groups
3. Given the following AWS setup, what will happen if the Internet Gateway is not attached to the VPC?
VPC: vpc-1234
Internet Gateway: igw-5678 (created but not attached)
EC2 Instance: in public subnet with route to igw-5678
medium
A. The EC2 instance will not have internet access
B. The EC2 instance will be terminated automatically
C. The EC2 instance will have internet access
D. The EC2 instance will have internet access only for outbound traffic

Solution

  1. Step 1: Understand Internet Gateway attachment requirement

    An Internet Gateway must be attached to the VPC to enable internet traffic flow. Without attachment, the gateway is inactive for that VPC.
  2. Step 2: Analyze the effect on EC2 instance

    Even if the route table points to the Internet Gateway, since it is not attached, the EC2 instance cannot send or receive internet traffic.
  3. Final Answer:

    The EC2 instance will not have internet access -> Option A
  4. Quick Check:

    Internet Gateway unattached = no internet access [OK]
Hint: Internet Gateway must be attached to VPC for internet access [OK]
Common Mistakes:
  • Assuming route table alone enables internet
  • Thinking instance auto-terminates without internet
  • Believing outbound-only access works without attachment
4. You created an Internet Gateway and attached it to your VPC, but your EC2 instance in the public subnet still cannot access the internet. What is the most likely cause?
medium
A. The Internet Gateway is not attached to the VPC
B. The EC2 instance is stopped
C. The route table for the subnet does not have a route to the Internet Gateway
D. The security group allows all traffic

Solution

  1. Step 1: Confirm Internet Gateway attachment

    The question states the Internet Gateway is attached to the VPC, so this is not the issue.
  2. Step 2: Check route table configuration

    For internet access, the subnet's route table must have a route directing 0.0.0.0/0 traffic to the Internet Gateway. Missing this route blocks internet access.
  3. Final Answer:

    The route table for the subnet does not have a route to the Internet Gateway -> Option C
  4. Quick Check:

    Route table missing IGW route = no internet [OK]
Hint: Check route table for 0.0.0.0/0 route to IGW [OK]
Common Mistakes:
  • Ignoring route table routes
  • Assuming attachment alone grants internet
  • Confusing security group rules with routing
5. You want to provide internet access to instances in a public subnet of your VPC. Which combination of steps is required to achieve this?
hard
A. Create a VPN connection and update the route table to route 0.0.0.0/0 to the VPN
B. Create a NAT Gateway, attach it to the VPC, and assign private IPs to instances
C. Attach an Internet Gateway to the subnet directly and assign Elastic IPs to instances
D. Create and attach an Internet Gateway to the VPC, update the subnet's route table to route 0.0.0.0/0 to the Internet Gateway, and ensure instances have public IPs

Solution

  1. Step 1: Attach Internet Gateway to VPC

    Internet Gateway must be created and attached to the VPC to enable internet connectivity.
  2. Step 2: Update subnet route table

    The route table for the public subnet must have a route sending all internet-bound traffic (0.0.0.0/0) to the Internet Gateway.
  3. Step 3: Assign public IPs to instances

    Instances need public IP addresses to communicate over the internet directly.
  4. Final Answer:

    Create and attach an Internet Gateway to the VPC, update the subnet's route table to route 0.0.0.0/0 to the Internet Gateway, and ensure instances have public IPs -> Option D
  5. Quick Check:

    IGW + route + public IP = internet access [OK]
Hint: Internet Gateway + route + public IP = public internet access [OK]
Common Mistakes:
  • Confusing NAT Gateway with Internet Gateway for public subnet
  • Trying to attach IGW to subnet directly
  • Forgetting to assign public IPs to instances