Outputs for cross-stack references in AWS - Time & Space 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.
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 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.
Each output added means one more export and one more import operation during deployment.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | About 20 (10 exports + 10 imports) |
| 100 | About 200 (100 exports + 100 imports) |
| 1000 | About 2000 (1000 exports + 1000 imports) |
Pattern observation: The number of operations grows directly with the number of outputs shared.
Time Complexity: O(n)
This means deployment time grows linearly as you add more outputs for cross-stack references.
[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.
Understanding how outputs affect deployment helps you design stacks that scale well and avoid slowdowns, a valuable skill in cloud architecture.
"What if we combined multiple values into a single output as a JSON string? How would the time complexity change?"