Hands-On: Deploy, Update & Delete a Stack

Create a stack from the template, preview changes safely, and clean up.

1 min read

A stack is one deployed copy of a template. The deploy command creates the stack the first time and updates it afterwards.

Try it

Terminal
# Create (or update) the stack
aws cloudformation deploy \
  --template-file template.yaml \
  --stack-name notesnap-dev \
  --parameter-overrides Stage=dev

# See the outputs
aws cloudformation describe-stacks --stack-name notesnap-dev \
  --query 'Stacks[0].Outputs'

# Preview the next change without applying it
aws cloudformation deploy --template-file template.yaml \
  --stack-name notesnap-dev --no-execute-changeset

# Clean up everything (except resources marked Retain)
aws cloudformation delete-stack --stack-name notesnap-dev

Change sets: look before you leap

A change set lists exactly what an update will do. Pay attention to the Replacement column. Changing some properties (like a DynamoDB table's key schema) replaces the resource, which means a new, empty table.

Watch out

Review replacements carefully on stateful resources (databases, buckets, tables). Use DeletionPolicy: Retain and UpdateReplacePolicy: Retain on anything holding important data.

Note

Templates that create IAM roles need --capabilities CAPABILITY_IAM (or CAPABILITY_NAMED_IAM). That's you explicitly acknowledging the stack can change permissions.

Key takeaways

  • `cloudformation deploy` creates or updates a stack from a template.
  • Change sets preview updates. Watch for resource replacement.
  • Protect stateful resources with Retain policies.

Check your understanding

Pick an answer to see the explanation.

  1. 1. A change set shows Replacement: True for your DynamoDB table. What does that mean?