Replacement, retention and rollback
Physical replacement is not a rename
CloudFormation resource properties document whether updates require no interruption, some interruption or replacement. Replacement means a new physical resource is needed; CloudFormation commonly creates it before redirecting references and disposing of the old one. For an explicitly named S3 bucket, changing BucketName requires replacement; keeping the same custom name can prevent a replacement. A new bucket does not automatically inherit existing objects. A logical ID change may appear as a removal and addition rather than a modification. Always inspect the preview and plan data migration separately.
Two retention policies, two triggers
DeletionPolicy: Retain preserves the physical resource when the stack is deleted or the resource is removed from the template during an update. UpdateReplacePolicy: Retain preserves the old physical resource when an update replaces it. These attributes sit beside Type and Properties, not inside Properties. Delete and Snapshot are other options, but Snapshot is supported only for certain types; defaults have exceptions. Retained resources leave stack management and may keep incurring charges. A retained resource is not a verified backup, and the policy does not stop someone with sufficient direct permissions from deleting it.
Roll back with evidence
If an update fails, CloudFormation can attempt to restore the previous stack configuration. Rollback may itself fail, producing UPDATE_ROLLBACK_FAILED. Read stack events, identify the first relevant failure, correct the underlying cause within approved scope, and use the documented continuation procedure when authorized. Skipping resources is a last-resort recovery decision and can leave actual state inconsistent with the template. Even a successful rollback does not guarantee restoration of application data or side effects. Test data restoration separately and verify health after the change.
Security and operational boundaries
Use a scoped CloudFormation service role and review who can pass or use it. Templates containing IAM resources may require CAPABILITY_IAM or, for custom-named IAM resources, CAPABILITY_NAMED_IAM. Acknowledgment is not a grant of permissions. Use supported dynamic references to Secrets Manager or Systems Manager Parameter Store for secrets, not plaintext outputs; check resource support and rotation behavior. Stack policies protect against selected stack update actions, not direct service calls. Termination protection and retention solve different problems. Avoid arbitrary macros and custom resources in this offline lab.
Practice: write a replacement gate
For the archive bucket, require a reviewed change set, tested restore, approved migration, budget for temporary duplicate storage, application verification and an explicit cleanup owner before any replacement is permitted. If a replacement is conditional, require clarification rather than assuming it is safe. For a simulated removal, identify which policy applies. Check that the retained old bucket is recorded for later authorized cleanup. No deployment, resource deletion or real credentials are needed.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Replacement, retention and rollback — knowledge check
Review a fictional infrastructure change without deploying AWS resources.
A stack update removes Archive from its template. Which policy controls retention in this case?
The Archive bucket is replaced during an update. Which attribute preserves the old bucket if set to Retain?
An old bucket is retained after replacement. What should the operator expect?
A rollback fails because an underlying resource cannot be restored. What is the safest next action?
What does CAPABILITY_NAMED_IAM acknowledge?