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

Stack Policies

Define policies to protect critical resources from being unintentionally updated or deleted during stack operations.

Stack Policies

What you'll learn: How to use stack policies to safeguard critical CloudFormation resources from accidental modification or deletion.


The Protection You Need

Stack policies act like a security lock on your CloudFormation stacks. While anyone with stack update permissions can normally modify any resource, a stack policy lets you define explicit rules that prevent certain resources from being updated or deleted during stack operations—even by administrators. Think of it as a "break glass in case of emergency" protection layer.

How Stack Policies Work

A stack policy is a JSON document you apply to a stack. It contains Allow and Deny statements that specify which actions (Update or Delete) are permitted on which resources. By default, once you attach a stack policy, all resources are protected (denied) unless you explicitly allow actions on them.

Here's the mental model: stack policies evaluate during stack updates. If a change set would modify a protected resource, CloudFormation blocks that operation unless you temporarily override the policy during the update.

When to Use Stack Policies

Use stack policies to protect:

  • Production databases from accidental replacement
  • S3 buckets containing critical data from deletion
  • IAM roles that shouldn't be modified without careful review
  • Any resource where unintended changes could cause data loss or downtime

You define the policy when creating the stack or add it later. The policy stays in effect until you explicitly modify or remove it.

Real-World Analogy

Imagine a filing cabinet with a lock on certain drawers. Everyone with the key can open the cabinet, but those specific drawers require an additional override procedure. Stack policies work the same way—they add an intentional friction layer to dangerous operations.

Key Takeaway:
Stack policies provide declarative protection rules that prevent accidental updates or deletions of critical CloudFormation resources, even from privileged users.