Updating and deleting stacks in AWS - Time & Space Complexity
When updating or deleting cloud stacks, it is important to understand how the time taken grows as the stack size changes.
We want to know how the number of resources affects the time to update or delete a stack.
Analyze the time complexity of updating and deleting a stack with multiple resources.
# Update stack with new template
aws cloudformation update-stack --stack-name MyStack --template-body file://template.yaml
# Delete stack
aws cloudformation delete-stack --stack-name MyStack
This sequence updates a stack by applying a new template and then deletes the stack.
Look at what happens repeatedly during update and delete.
- Primary operation: Processing each resource in the stack during update or delete.
- How many times: Once per resource in the stack.
As the number of resources grows, the time to update or delete grows roughly in direct proportion.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | About 10 resource operations |
| 100 | About 100 resource operations |
| 1000 | About 1000 resource operations |
Pattern observation: The number of operations grows linearly with the number of resources.
Time Complexity: O(n)
This means the time to update or delete a stack grows directly with the number of resources it contains.
[X] Wrong: "Updating or deleting a stack takes the same time no matter how many resources it has."
[OK] Correct: Each resource must be processed, so more resources mean more work and more time.
Understanding how stack operations scale helps you design efficient cloud deployments and shows you grasp real-world cloud management challenges.
"What if the stack uses nested stacks? How would that affect the time complexity of updating or deleting?"