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

Stack Drift Detection

Learn how to detect configuration drift between stack templates and actual resource state in AWS.

Stack Drift Detection

You'll learn how to identify when your actual AWS resources no longer match what your CloudFormation template declares.

What Is Stack Drift?

Imagine you wrote down a recipe for your infrastructure in a CloudFormation template and used it to create a stack. Over time, someone (or something) manually changes resources directly in the AWS console—maybe they resized an EC2 instance or modified a security group rule. Now your actual infrastructure doesn't match your template anymore. This mismatch is called drift.

Drift detection is CloudFormation's way of comparing what your template says should exist with what actually exists in AWS.

Why Drift Happens

Drift occurs when:

  • Engineers make manual changes through the AWS console
  • Other automation tools modify resources
  • Out-of-band scripts update configurations
  • Third-party integrations alter resource properties

How Drift Detection Works

CloudFormation inspects each resource in your stack and compares its current state against the template's declared configuration. It reports three possible statuses:

  • IN_SYNC: Resource matches the template perfectly
  • MODIFIED: Resource has drifted from the template
  • DELETED: Resource no longer exists
  • NOT_CHECKED: Resource type doesn't support drift detection

You initiate drift detection through the CloudFormation console or CLI, and CloudFormation generates a detailed report showing exactly which properties have changed and their current vs. expected values.

When to Use It

Run drift detection regularly (especially before stack updates) to ensure your template remains the "single source of truth" for your infrastructure. Catching drift early prevents unexpected changes during updates and helps maintain infrastructure-as-code discipline.

Key Takeaway: Stack Drift Detection helps you identify and reconcile differences between your CloudFormation template and actual resource state, ensuring your infrastructure remains predictable and manageable.