AWS › IaC (CloudFormation)

How does CloudFormation calculate and apply changes when you update an existing stack, and what is a change set?

Intermediate

Answer

When you update a stack, CloudFormation compares the new template against the currently deployed configuration to determine exactly what resources need to be created, modified, or deleted, and a change set lets you preview this calculated plan before actually applying it, showing you precisely what will happen, which is especially valuable for catching an unexpected or potentially destructive change, such as a resource being replaced entirely rather than simply updated, before it actually occurs in a production environment.
aws cloudformation create-change-set --stack-name my-stack --template-body file://updated-template.yaml --change-set-name my-changes
Real-world example A team reviews a CloudFormation change set before applying an update to their production stack, discovering that a seemingly minor configuration change would actually have caused their database to be completely replaced, and they revise their template to avoid this destructive and unintended change.

Common follow-ups: What types of changes typically require a resource to be replaced rather than simply updated?;How do you approve and execute a reviewed change set?