Course contentsShow
← Cloud and Infrastructure
Lesson 877 of 2,98916. AWS CloudFormationFree lesson

Stack Creation and Lifecycle

Learn how CloudFormation stacks are created, updated, and deleted, including rollback behavior and stack states.

What You'll Learn

You'll understand how CloudFormation stacks move through creation, updates, and deletion, and what happens when things go wrong.

Understanding Stack Lifecycle

A CloudFormation stack is a living entity with distinct lifecycle phases. Think of it like constructing a building: you lay the foundation, add floors, make renovations, and eventually demolish it if needed.

Stack States

When you create or modify a stack, it transitions through various states:

  • CREATE_IN_PROGRESS: CloudFormation is provisioning resources
  • CREATE_COMPLETE: All resources successfully created
  • CREATE_FAILED: Creation failed; stack may be rolled back
  • UPDATE_IN_PROGRESS: Modifying existing resources
  • UPDATE_COMPLETE: Update succeeded
  • DELETE_IN_PROGRESS: Tearing down resources
  • DELETE_COMPLETE: Stack fully removed
  • ROLLBACK_IN_PROGRESS: Undoing failed changes

Creation Process

When you submit a template, CloudFormation:

  1. Validates the template syntax
  2. Determines resource dependencies
  3. Creates resources in the correct order
  4. Waits for each resource to reach a stable state

If any resource fails, CloudFormation automatically rolls back by deleting successfully created resources, returning to the previous stable state.

Update Behavior

Updates follow a similar pattern but preserve existing resources when possible. CloudFormation determines whether each resource needs replacement, modification, or no change.

Deletion Process

During deletion, CloudFormation removes resources in reverse dependency order. Resources with DeletionPolicy: Retain survive stack deletion (like keeping photos before demolishing a house).

Rollback Scenarios

Rollbacks protect you from partial failures. If creation fails, you typically get CREATE_FAILED → ROLLBACK_IN_PROGRESS → ROLLBACK_COMPLETE. For updates: UPDATE_ROLLBACK_IN_PROGRESS → UPDATE_ROLLBACK_COMPLETE.

Key Takeaway: CloudFormation stacks have predictable lifecycles with automatic rollback protection—failed operations won't leave you with half-built infrastructure orphaned in your account.