Creating a custom VPC in AWS - Performance & Efficiency
When creating a custom Virtual Private Cloud (VPC), it's important to understand how the time to set it up changes as you add more parts.
We want to know how the number of steps grows when we add more subnets or gateways.
Analyze the time complexity of the following operation sequence.
// Create a VPC
aws ec2 create-vpc --cidr-block 10.0.0.0/16
// Create multiple subnets
for subnet in subnets:
aws ec2 create-subnet --vpc-id vpc-12345 --cidr-block subnet.cidr
// Create an internet gateway
aws ec2 create-internet-gateway
// Attach the internet gateway to the VPC
aws ec2 attach-internet-gateway --vpc-id vpc-12345 --internet-gateway-id igw-12345
This sequence creates one VPC, several subnets inside it, and an internet gateway attached to the VPC.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Creating subnets inside the VPC.
- How many times: Once per subnet you want to add.
Each subnet requires one API call to create it. So, if you add more subnets, the total calls increase directly with the number of subnets.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 1 (VPC) + 10 (subnets) + 1 (gateway) + 1 (attach) = 13 |
| 100 | 1 + 100 + 1 + 1 = 103 |
| 1000 | 1 + 1000 + 1 + 1 = 1003 |
Pattern observation: The total operations grow roughly in a straight line as you add more subnets.
Time Complexity: O(n)
This means the time to create the VPC setup grows directly with the number of subnets you add.
[X] Wrong: "Creating more subnets will take the same time as creating just one."
[OK] Correct: Each subnet requires its own creation step, so more subnets mean more steps and more time.
Understanding how setup time grows with added resources helps you design scalable cloud networks and shows you think about real-world impacts.
"What if we created multiple internet gateways instead of just one? How would the time complexity change?"