0
0
AWScloud~5 mins

Creating stacks in AWS - Performance & Efficiency

Choose your learning style9 modes available
Time Complexity: Creating stacks
O(n)
Understanding Time Complexity

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.

Scenario Under Consideration

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.

Identify Repeating Operations

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.
How Execution Grows With Input

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
10About 10 resource provisioning calls
100About 100 resource provisioning calls
1000About 1000 resource provisioning calls

Pattern observation: The number of operations grows directly with the number of resources.

Final Time Complexity

Time Complexity: O(n)

This means the time to create the stack grows linearly with the number of resources.

Common Mistake

[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.

Interview Connect

Understanding how resource count affects stack creation time helps you design efficient infrastructure and explain trade-offs clearly in interviews.

Self-Check

"What if the stack uses nested stacks? How would that affect the time complexity of creating the overall stack?"