Deploying: stacks & events

create, update, rollback, delete.

Beginner12 min · lesson 4 of 12

You deploy a template by creating a stack — via the console, the CLI, or (in practice) automation. CloudFormation reads the template, orders the resources by their dependencies, and calls the AWS APIs to create each one, emitting a stream of stack events as it goes. The stack lands in CREATE_COMPLETE when every resource succeeds, and you watch the events to follow progress or find the exact resource that failed.

terminal
$ aws cloudformation deploy \
--template-file template.yaml \
--stack-name payments-network \
--parameter-overrides Environment=prod InstanceType=t3.large
$ aws cloudformation describe-stack-events --stack-name payments-network \
--query "StackEvents[0:3].[LogicalResourceId,ResourceStatus]" --output table

Update, rollback, delete

Updating a stack means editing the template (or parameters) and applying it; CloudFormation computes what changed and modifies only those resources. The safety net is automatic rollback: if any resource fails during a create or update, CloudFormation reverts the whole stack to its last known-good state rather than leaving it half-built. Deleting a stack removes its resources in reverse dependency order.

Stack lifecycle
1CREATE
provision resources
2UPDATE
change what differs
3ROLLBACK
auto-revert on failure
4DELETE
remove in reverse order
Rollback is the safety net: a failed update returns the stack to its previous working state.
Protect stateful resources from deletion
A stack delete (or a replacement during update) can destroy a database or bucket with its data. Set DeletionPolicy: Retain (or Snapshot) on stateful resources so they survive a stack deletion, and turn on termination protection for production stacks so nobody deletes the whole stack by accident. Rollback protects updates; these protect against deletion.