Changing stacks safely

Advanced · 2 min

Change sets, update behaviours and replacement, drift, stack policies, termination protection, rollback alarms, stuck rollbacks and StackSets.

Before thisCloudFormation templates and stacks

AWS Events · 13 min · from 11:32

Changing stacks safely

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by AWS EventsReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Each property has an update behaviour: no interruption, some interruption, or replacement. Replacement means a new physical resource.
  • Create a change set and read it before executing. Look for Replacement and Remove on anything that holds data.
  • UpdateReplacePolicy protects the old resource when it is replaced, and DeletionPolicy protects it when it is removed. Set both on data.
  • Drift is a change made outside the stack. Drift detection reports it, and a drift-aware change set can plan to revert it.
  • Termination protection, stack policies and alarm-based rollback triggers are separate guards against separate mistakes.
  • UPDATE_ROLLBACK_FAILED is fixed by repairing the cause and continuing the rollback, not by deleting the stack.

A one-line edit can delete a database

In a template, changing a tag and changing a database’s port look the same: one line. Their effects don’t. Every property has a documented update behaviour:

  • No interruption: changed in place, nothing notices.
  • Some interruption: changed in place, with a restart or gap.
  • Replacement: a new resource is created with a new physical ID, references are moved, and the old one is deleted.

Changing an RDS instance’s Port, for example, replaces the instance. The new one is empty. It’s like being told “we can update your office number” and discovering it means demolishing the building.

Look before you execute

A change set is CloudFormation’s preview, the counterpart of a Terraform plan.

aws cloudformation create-change-set --stack-name shop \
  --change-set-name release-42 --template-body file://shop.yaml
aws cloudformation describe-change-set --stack-name shop \
  --change-set-name release-42
aws cloudformation execute-change-set --stack-name shop \
  --change-set-name release-42

For each resource you get an action (Add, Modify, Remove) and, for modifications, whether replacement will happen: True, False or Conditional. In a pipeline, fail the build or demand approval when a stateful resource shows replacement or removal.

I tried this against moto, a local emulator, changing one queue’s name in an existing stack. It reported both resources in the template as Add, which is plainly wrong. Change set semantics are exactly the kind of thing an emulator doesn’t model, so rehearse on a real non-production stack.

Pre-deployment validation now runs on create, update and change set operations, catching bad property syntax, name collisions and some other common causes of failure before anything is provisioned. It reduces surprises; it doesn’t guarantee success.

Guard the things you can’t recreate

Guard Protects against
UpdateReplacePolicy losing the old resource during replacement
DeletionPolicy losing it when removed or when the stack is deleted
Stack policy updates that modify or replace named resources
Termination protection someone deleting the whole stack
IAM and service roles who may do any of this

A stack policy applies only during stack updates and is not access control; once set, everything is protected until explicitly allowed. These layers overlap on purpose.

Watch it after it lands

“All resources updated” says nothing about whether the application works. Rollback triggers attach CloudWatch alarms to a create or update. If one goes into ALARM during the operation or a monitoring period of up to 180 minutes afterwards, CloudFormation rolls back.

Drift

Someone fixes an incident in the console. Now reality and the template disagree: that is drift. Drift detection compares live properties with what the stack expects. It only checks properties you set explicitly, not defaults.

A normal change set compares new template with old template, so it can miss the manual edit. A drift-aware change set, created with --deployment-mode REVERT_DRIFT, compares the new template, the old one and the live state, and shows what reverting would do. Read it carefully: the hand edit may be what’s keeping production up. Put it in the template first.

When a rollback fails

If an update fails, CloudFormation rolls back. If the rollback also fails, often because something was deleted or changed by hand, the stack stops in UPDATE_ROLLBACK_FAILED. Find the first failed event, repair the cause (recreate the missing dependency, grant the permission), then use continue update rollback, skipping a resource only as a last resort and reconciling it afterwards.

Restructuring and fleets

Renaming a logical ID reads as delete plus create. Stack refactoring moves or renames resources between and within stacks while keeping them, and resource import adopts existing resources. StackSets deploy one template to many accounts and Regions; roll out in waves with a low failure tolerance, so a bad template stops early. Keep stacks small enough that a failed update has a small blast radius.

About the video

The embed is a clip (11:32 to 24:40) of AWS re:Invent 2025’s “AWS infrastructure as code: A year in review”. Its chapters in that range are improving developer speed, optimising deployment and safely managing drift. It is a feature update, not a beginner tutorial, so read the mechanics above first. I judged it from chapters and description only, since transcripts couldn’t be fetched. English was judged from its English caption track and title. A short change set demo is in deeper.

What was run: only the moto change set, reported above as an emulator failure. moto’s drift detection call errored. Everything about CloudFormation behaviour is from the AWS docs, checked 2026-11-29; the commands weren’t run against AWS.

Where this fits

Writing YAML by hand gets long. The next lesson generates it from code with the AWS CDK.

Check yourself

  1. 01A change set shows Replacement True for your database. You set DeletionPolicy Retain. Is your data safe?

    Not from that setting alone. DeletionPolicy covers removal from the stack and stack deletion. Set UpdateReplacePolicy for replacement, and even then the new database is empty unless you restore into it.

  2. 02Someone widened a security group by hand last week. Today's template change does not touch it. Will a normal update revert the edit?

    Do not count on it. A normal change set compares templates, not live state. Run drift detection, or use a drift-aware change set, which compares the live resource too.

  3. 03An update deployed cleanly but the error rate tripled. What could have made CloudFormation undo it automatically?

    A rollback trigger: a CloudWatch alarm on the error rate, attached to the operation, with a monitoring period after resources finish updating.

  4. 04You rename a logical ID to tidy the template. What does CloudFormation think you did?

    Removed one resource and added another. It will create a new physical resource and delete the old one. Use stack refactoring to rename or move resources while keeping them.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark