Internet Gateway for public access in AWS - Time & Space Complexity
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?"