Stacks, Parameters, and Outputs
~10 min read
How CloudFormation organizes resources into a manageable unit, and makes templates reusable across environments.
A Stack is CloudFormation's fundamental unit of management — every resource defined in a template becomes part of that stack when deployed, and CloudFormation tracks the relationship between the stack and its resources, enabling operations on the whole group at once (update everything together, or delete everything together cleanly).
Parameters let a template accept input values at deployment time rather than hardcoding them — an instance type, an environment name, a database password (ideally referenced from Secrets Manager rather than passed as plain text) — making the same template genuinely reusable across different environments or accounts by supplying different parameter values each time, rather than needing a separate, duplicated template per environment.
Outputs let a stack expose specific values (like a created load balancer's DNS name, or a VPC's ID) for use outside the stack — either for a human to reference, or, more powerfully, for a different CloudFormation stack to import via cross-stack references, enabling infrastructure to be split into logically separate, more manageable stacks (e.g. a networking stack and an application stack) that still reference each other's resources cleanly.
💻 Code example
Parameters:
EnvironmentName:
Type: String
AllowedValues: [dev, staging, prod]
InstanceType:
Type: String
Default: t3.micro
Resources:
WebServer:
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref InstanceType
Tags:
- Key: Environment
Value: !Ref EnvironmentName
Outputs:
InstanceId:
Value: !Ref WebServer
💬 Deep Dive with AI
Key points
- •A Stack is the deployable, manageable unit grouping all resources from one template
- •Parameters make one template reusable across environments/accounts with different input values
- •Outputs expose specific stack values for external use, including cross-stack references
- •Splitting infrastructure into multiple logically-related stacks (using outputs/cross-stack references) improves manageability over one giant monolithic template