Lesson 2 of 5 AWS CloudFormation

Updating Stacks Safely and Detecting Drift

This lesson explains how to update CloudFormation stacks safely and find changes made outside CloudFormation, which is most of the operational work after a stack is created.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain update behaviours, including replacement.
  • Preview updates with change sets.
  • Detect and resolve drift.

Updates and replacement

When a template or parameter changes, CloudFormation compares desired and current state and updates each affected resource in one of three ways, depending on the property. Update with no interruption changes the resource in place, for example adding a tag. Update with some interruption keeps the physical resource but interrupts it, for example changing an EBS-backed instance type, which stops and starts the instance. Replacement creates a new resource with a new physical ID and deletes the old one, for example changing an RDS DB instance's identifier or an EC2 instance's AMI or subnet. Replacement of stateful resources can lose data, so it must be identified before the update.

The following diagram shows an example of each update behaviour.

The three ways CloudFormation updates a resource, depending on the property changed. Update with no interruption changes it in place, such as adding a tag. Update with some interruption keeps the physical resource but interrupts it, such as an EBS-backed instance type change that stops and starts the instance. Replacement creates a new resource and deletes the old one.
The CloudFormation reference for each property states which behaviour a change causes.
Sort into groups

What does the update do?

Exam skills 3.1.2

Decide the update behaviour of each property change.

Log in to try this activity Interactive activities are free with an account.

Change sets

A change set shows exactly what an update will do before it is executed: each resource to be added, modified or removed, and whether a modification requires replacement (True, False or Conditional). Teams review change sets, then execute or delete them. Change sets can also be used to create stacks and to import existing resources into a stack (resource import), and the IaC generator creates templates from existing resources that were created manually.

aws cloudformation create-change-set --stack-name web-prod --change-set-name ami-2026-10 \
  --use-previous-template --parameters ParameterKey=LatestAmi,ParameterValue=/golden/al2023/latest \
  ParameterKey=Env,UsePreviousValue=true
aws cloudformation describe-change-set --stack-name web-prod --change-set-name ami-2026-10 \
  --query 'Changes[].ResourceChange.[LogicalResourceId,Action,Replacement]' --output table
aws cloudformation execute-change-set --stack-name web-prod --change-set-name ami-2026-10

Drift detection

Drift is a difference between a resource's actual configuration and its template definition, caused by manual changes in the console or CLI. Drift detection checks a stack (or a single resource, or all stacks of a StackSet) and reports each resource as IN_SYNC, MODIFIED, DELETED or NOT_CHECKED, with property-level differences. It does not fix drift: you either update the template to match reality or revert the manual change, and the next stack update may overwrite or fail on drifted properties. An AWS Config managed rule (cloudformation-stack-drift-detection-check) can check for drift on a schedule.

Scenario questions

Handling drift

Exam skills 3.1.2 · 3.1.3

Respond to manual changes in stack resources.

Log in to try this activity Interactive activities are free with an account.
Worked example

An update that would replace a database

An engineer changes the DBInstanceIdentifier property in a template to follow a new naming standard. The change set shows Modify with Replacement: True for the database. Executing it would create a new, empty database and delete the old one (after a snapshot only if a DeletionPolicy or UpdateReplacePolicy of Snapshot is set). The team discards the change set and leaves the identifier unchanged. Reviewing change sets for replacement of stateful resources is now a mandatory step in their release checklist.

Check yourself

Does drift detection fix manual changes?

Show answer

No. It reports them; you must update the stack or the resource yourself.

Exam Tips

Remember for the exam

  • Updates happen with no interruption, some interruption, or replacement depending on the property.
  • Change sets preview additions, modifications, removals and replacements.
  • Drift detection reports manual changes but does not fix them.
  • IaC generator and resource import bring existing resources under CloudFormation.