A CloudFormation change set is a preview of the changes that CloudFormation will make to your stack when you update it. Instead of applying an update immediately, you create a change set, review the proposed additions, modifications, and deletions, and then decide whether to execute it. Change sets let you catch unintended replacements or deletions before they affect running resources.
Background: Why Change Sets Exist
AWS CloudFormation is an infrastructure-as-code service that creates and manages AWS resources from templates. When you update a stack, CloudFormation compares the new template with the current stack state and generates a plan. Without a change set, that plan is applied as soon as you submit the update. For simple stacks this is fine, but for production environments even a small template edit can have large consequences—for example, changing a property that forces the replacement of an EC2 instance or a database. Change sets were introduced to give operators a review step. They show exactly which resources will be added, modified, or removed, and whether a resource will be replaced. This makes updates auditable and reduces the risk of accidental downtime or data loss.
How Change Sets Work
Creating a change set does not modify your stack. CloudFormation evaluates the new template against the existing stack and produces a list of changes. Each change includes the logical resource ID, the action (Add, Modify, Remove), and for modifications, the replacement type (False, True, Conditional). A replacement type of True means the resource will be recreated, which can cause downtime or data loss if the resource holds state. Conditional means replacement depends on other factors, often requiring manual review. The change set also includes the before and after property values for modified resources.
After reviewing, you can execute the change set to apply the changes, or delete it. Change sets are immutable once created; to alter the proposed changes, you create a new change set. You can create multiple change sets for the same stack, but only one can be executed at a time. If the stack changes after a change set is created (for example, another update is applied), the change set becomes stale and cannot be executed.
Creating and Reviewing a Change Set
The typical workflow involves these steps:
- Prepare an updated template or a new version of the template.
- Create a change set using the AWS Management Console, AWS CLI, or SDKs. You specify the stack, the new template, and optionally parameters and capabilities.
- Wait for the change set status to reach CREATE_COMPLETE.
- Review the changes: inspect each resource change, paying special attention to replacements and removals.
- If the changes are acceptable, execute the change set. Otherwise, delete it and revise the template.
When reviewing, look for resources with action Remove—these will be deleted. Also check for Modify with replacement True, as these will be recreated. For example, changing the AMI ID of an EC2 instance typically triggers replacement, causing downtime unless behind a load balancer. Changing a security group rule might modify in place without replacement.
Common Problems and Limitations
Change sets are not perfect. They do not detect changes to resources that are not managed by CloudFormation, and they may not show the full impact of updates to nested stacks. For nested stacks, you must create change sets for each nested stack separately. Also, change sets do not evaluate the effects of drift—if a resource has been manually modified outside CloudFormation, the change set may not reflect the true current state. Additionally, some resource properties are not fully captured; for instance, changes to certain IAM policies might not show detailed diffs. Another limitation: change sets do not support all resource types equally; some resources may show as modified without clear property-level details. Finally, change sets cannot be used for stack creation—only for updates.
Change Sets vs. Other Deployment Tools
Change sets are specific to CloudFormation. Other infrastructure-as-code tools like Terraform use a plan phase that serves a similar purpose. Compared to CloudFormation's own drift detection, change sets focus on proposed updates rather than current state deviations. Drift detection tells you what has changed outside CloudFormation; change sets tell you what CloudFormation will change. Both are useful for maintaining stack integrity. For organizations using CI/CD pipelines, change sets can be integrated to require manual approval before execution, adding a safety gate.
Best Practices for Using Change Sets
- Always create a change set before updating production stacks.
- Automate change set creation in pipelines and require approval for execution.
- Pay close attention to resources marked for replacement; consider blue/green deployment strategies for stateful resources.
- Regularly check for drift to ensure change sets are based on accurate current state.
- Use descriptive names for change sets to track their purpose.
- Delete stale change sets to avoid confusion.
Frequently Asked Questions
Can I execute a change set if the stack has drifted?
Yes, but the change set is based on the stack's last known state, not the drifted state. Executing it may overwrite manual changes. It is safer to resolve drift first.
How long does a change set take to create?
Creation time varies by stack size and resource types, typically from a few seconds to several minutes. Large stacks with many resources may take longer.
Can I create a change set for a stack that is in a failed state?
No, the stack must be in a stable state (CREATE_COMPLETE, UPDATE_COMPLETE, or UPDATE_ROLLBACK_COMPLETE) to create a change set.
What happens if I execute a change set after the stack has been updated?
The change set becomes stale and cannot be executed. You must create a new change set based on the current stack.
Do change sets cost anything?
CloudFormation itself is free, but the resources created or modified by executing a change set may incur charges according to the pricing of those services.
Can I use change sets with nested stacks?
Yes, but you need to create change sets for each nested stack individually. The parent stack change set will not automatically include changes to nested stacks.