3.2.3. Change Management with CloudFormation
š” First Principle: CloudFormation facilitates controlled, auditable, and repeatable changes to infrastructure, minimizing disruption and enabling robust rollback strategies for maintaining operational stability.
Scenario: You need to update a production CloudFormation stack that manages critical EC2 instances and an RDS database. You want to review the exact changes before applying them and ensure that the database is protected from accidental deletion during the update.
For SysOps Administrators, managing changes to infrastructure is a critical operational task. AWS CloudFormation provides features that support controlled change management, reducing risks associated with updates.
Key Concepts of Change Management with CloudFormation:
- Version Control: CloudFormation templates should be stored in a version control system (Git), allowing you to track all infrastructure changes, see who made them, and revert to previous versions if needed.
- Change Sets: (Allow you to preview the changes that CloudFormation will make to your stack before you execute them.) You can use change sets to understand the impact of a proposed update to a running stack before applying it. This helps identify unintended modifications or deletions.
- Automated Rollback on Failure: If any resource fails to provision or update during a stack operation, CloudFormation automatically rolls back all changes to the previous stable state by default. This minimizes the impact of failed deployments.
- Stack Policies: (Prevent unintended updates or deletions to specific stack resources.) You can define stack policies to protect critical resources (e.g., production databases) from being updated or deleted accidentally.
- Drift Detection: (Identifies when actual resource configurations deviate from the template's defined state.) Helps SysOps Administrators identify manual changes made out-of-band and correct "configuration drift."
ā ļø Common Pitfall: Not using Change Sets to preview changes before applying them to production stacks, leading to unexpected resource modifications or deletions.
Key Trade-Offs: Automated rollback (faster recovery, but might hide underlying issues) versus manual troubleshooting (slower, but deeper understanding of failure).
Practical Implementation: Creating a CloudFormation Change Set via CLI:
aws cloudformation create-change-set \
--stack-name MyProductionStack \
--template-body file://updated-template.yaml \
--change-set-name "UpdateWebAppVersion" \
--change-set-type UPDATE
Then, to view the changes:
aws cloudformation describe-change-set \
--change-set-name "UpdateWebAppVersion" \
--stack-name MyProductionStack
Reflection Question: How does CloudFormation's support for change sets (for previewing changes) and stack policies (for preventing unintended modifications) facilitate controlled, auditable, and repeatable changes to infrastructure, minimizing disruption and enabling robust rollback strategies?