0
0
AWScloud~5 mins

Outputs for cross-stack references in AWS - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Outputs for cross-stack references
O(n)
Understanding Time Complexity

When using outputs to share information between AWS stacks, it's important to understand how the number of outputs affects deployment time.

We want to know how the time to deploy grows as we add more outputs for cross-stack references.

Scenario Under Consideration

Analyze the time complexity of exporting multiple outputs from one stack and importing them in another.

Outputs:
  Output1:
    Value: !Ref Resource1
    Export:
      Name: Resource1Export
  Output2:
    Value: !GetAtt Resource2.Attribute
    Export:
      Name: Resource2Export
  ...

In another stack:
Resources:
  MyResource:
    Properties:
      Property1: !ImportValue Resource1Export
      Property2: !ImportValue Resource2Export

This sequence exports multiple values from one stack and imports them in another to share resources.

Identify Repeating Operations

Identify the API calls, resource provisioning, data transfers that repeat.

  • Primary operation: Reading and writing CloudFormation stack outputs and imports.
  • How many times: Once per output exported and once per output imported.
How Execution Grows With Input

Each output added means one more export and one more import operation during deployment.

Input Size (n)Approx. Api Calls/Operations
10About 20 (10 exports + 10 imports)
100About 200 (100 exports + 100 imports)
1000About 2000 (1000 exports + 1000 imports)

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

Final Time Complexity

Time Complexity: O(n)

This means deployment time grows linearly as you add more outputs for cross-stack references.

Common Mistake

[X] Wrong: "Adding more outputs won't affect deployment time much because they are just simple values."

[OK] Correct: Each output requires CloudFormation to process and validate exports and imports, so more outputs mean more work and longer deployment times.

Interview Connect

Understanding how outputs affect deployment helps you design stacks that scale well and avoid slowdowns, a valuable skill in cloud architecture.

Self-Check

"What if we combined multiple values into a single output as a JSON string? How would the time complexity change?"