Internet Gateway for public access in AWS - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When setting up an Internet Gateway for public access, it's important to understand how the time to complete this setup changes as the network grows.
We want to know how the number of steps or calls grows when we add more resources.
Analyze the time complexity of the following operation sequence.
# Create a VPC
aws ec2 create-vpc --cidr-block 10.0.0.0/16
# Create an Internet Gateway
aws ec2 create-internet-gateway
# Attach the Internet Gateway to the VPC
aws ec2 attach-internet-gateway --internet-gateway-id igw-12345678 --vpc-id vpc-12345678
# Update route table to direct traffic to the Internet Gateway
aws ec2 create-route --route-table-id rtb-12345678 --destination-cidr-block 0.0.0.0/0 --gateway-id igw-12345678
This sequence creates a VPC, an Internet Gateway, attaches the gateway to the VPC, and updates the route table to allow public internet access.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Creating and attaching one Internet Gateway and updating one route table.
- How many times: Each step is done once per VPC setup.
As you add more VPCs, you repeat these steps for each VPC.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 VPCs | ~40 calls (4 per VPC) |
| 100 VPCs | ~400 calls |
| 1000 VPCs | ~4000 calls |
Pattern observation: The number of API calls grows directly with the number of VPCs.
Time Complexity: O(n)
This means the time to set up Internet Gateways grows in a straight line as you add more VPCs.
[X] Wrong: "Adding more VPCs will not increase the number of API calls because the Internet Gateway is shared."
[OK] Correct: Each VPC needs its own Internet Gateway and route table update, so calls increase with each VPC.
Understanding how setup steps grow with network size helps you plan and explain cloud infrastructure scaling clearly and confidently.
"What if we attached one Internet Gateway to multiple VPCs? How would the time complexity change?"
Practice
Internet Gateway in AWS?Solution
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.Step 2: Identify the correct purpose
Among the options, only allowing communication between a VPC and the internet matches the Internet Gateway's function.Final Answer:
To allow communication between a VPC and the internet -> Option AQuick Check:
Internet Gateway = Connects VPC to internet [OK]
- Confusing Internet Gateway with storage services
- Thinking it manages user permissions
- Assuming it creates private subnets
Solution
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.Step 2: Match the correct AWS resource
Among the options, only a VPC is the correct resource to attach an Internet Gateway to.Final Answer:
A Virtual Private Cloud (VPC) -> Option BQuick Check:
Internet Gateway attaches to VPC [OK]
- Trying to attach Internet Gateway directly to EC2
- Confusing with storage like S3 buckets
- Thinking it attaches to Security Groups
VPC: vpc-1234
Internet Gateway: igw-5678 (created but not attached)
EC2 Instance: in public subnet with route to igw-5678
Solution
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.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.Final Answer:
The EC2 instance will not have internet access -> Option AQuick Check:
Internet Gateway unattached = no internet access [OK]
- Assuming route table alone enables internet
- Thinking instance auto-terminates without internet
- Believing outbound-only access works without attachment
Solution
Step 1: Confirm Internet Gateway attachment
The question states the Internet Gateway is attached to the VPC, so this is not the issue.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.Final Answer:
The route table for the subnet does not have a route to the Internet Gateway -> Option CQuick Check:
Route table missing IGW route = no internet [OK]
- Ignoring route table routes
- Assuming attachment alone grants internet
- Confusing security group rules with routing
Solution
Step 1: Attach Internet Gateway to VPC
Internet Gateway must be created and attached to the VPC to enable internet connectivity.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.Step 3: Assign public IPs to instances
Instances need public IP addresses to communicate over the internet directly.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 DQuick Check:
IGW + route + public IP = internet access [OK]
- Confusing NAT Gateway with Internet Gateway for public subnet
- Trying to attach IGW to subnet directly
- Forgetting to assign public IPs to instances
