Creating stacks in AWS - Performance & Efficiency
When creating stacks in AWS, it is important to understand how the time to create resources grows as the number of resources increases.
We want to know how the total time or operations scale when we add more resources to a stack.
Analyze the time complexity of creating an AWS CloudFormation stack with multiple resources.
aws cloudformation create-stack \
--stack-name MyStack \
--template-body file://template.yaml \
--parameters ParameterKey=InstanceType,ParameterValue=t2.micro
This command creates a stack that provisions all resources defined in the template.
When creating a stack, AWS performs these operations:
- Primary operation: Provisioning each resource defined in the template.
- How many times: Once per resource in the stack.
As the number of resources in the template grows, the number of provisioning operations grows roughly the same way.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | About 10 resource provisioning calls |
| 100 | About 100 resource provisioning calls |
| 1000 | About 1000 resource provisioning calls |
Pattern observation: The number of operations grows directly with the number of resources.
Time Complexity: O(n)
This means the time to create the stack grows linearly with the number of resources.
[X] Wrong: "Creating a stack takes the same time no matter how many resources it has."
[OK] Correct: Each resource needs to be created, so more resources mean more work and more time.
Understanding how resource count affects stack creation time helps you design efficient infrastructure and explain trade-offs clearly in interviews.
"What if the stack uses nested stacks? How would that affect the time complexity of creating the overall stack?"