
Common use cases
- Prevent accidental configuration changes to critical resources (for example, locking down an S3 bucket or a production RDS instance).
- Enforce permissions during automated deployment pipelines so certain stacks cannot be altered by routine updates.
- Combine with change sets to preview and validate whether proposed changes will be blocked.
- This example denies all update actions on the logical resource
MyS3Bucket, while leaving other resources updatable:
- To apply the above policy to a stack:
- To retrieve the current stack policy for a stack:
Best practices
- Limit Deny rules to only the truly critical resources. Overly broad Deny rules can block legitimate and necessary updates.
- Use change sets to preview proposed updates and confirm whether the stack policy will block any changes before applying them.
- Combine stack policies with resource-level DeletionPolicy attributes when you need both update and deletion protection.
- Keep stack policies versioned alongside your infrastructure-as-code to track intent and changes over time.
Use change sets and a CI/CD review step to validate changes against your stack policy before applying updates to production stacks. This reduces the risk of blocked deployments and accidental drift.
Stack policies are enforced only during stack update operations. They do not replace a resource’s DeletionPolicy — if you must prevent deletion, configure the resource’s DeletionPolicy or use other safeguards.
- AWS CloudFormation — Update stacks and change sets
- CloudFormation DeletionPolicy attribute
- AWS CLI — cloudformation set-stack-policy
- Kubernetes Documentation (related infrastructure best practices)