Stack policies
Stack policies in AWS CloudFormation prevent unplanned resource updates or deletions. They define what changes are allowed and which resources are protected during stack modifications. A stack policy is a JSON-formatted text file that specifies the allowed or denied actions on defined resources or the entire stack. By implementing stack policies, you can reduce the risk of unintended modifications to critical resources during maintenance or updates, ensuring stability during the cloud infrastructure lifecycle.
Guide on AWS CloudFormation Stack Policies
What is it: Stack policies are JSON documents that define the update actions that can be performed on designated resources.
Why it is important: Stack policies provide an additional level of security by preventing unintentional updates to stack resources, which can help protect critical resources from being accidentally deleted or updated.
How it works: They control how AWS CloudFormation manages updates to particular resources in an AWS CloudFormation stack. When you associate a policy with your stack, CloudFormation checks the policy when you submit an update request.
Answering Questions on Stack Policies: When answering an exam question about stack policies, keep in mind that stack policies provide protection for resources, limiting the actions that can be taken on them. Use a policy to prevent stack resources from being unintentionally updated or deleted during stack operations. Always remember, stack policy doesn’t prevent or roll back resource updates that are initiated outside of AWS CloudFormation(i.e., updates initiated through a different service).
Exam Tips: Understanding the syntax and key components of stack policies is an important part of succeeding in the exam. Recognize the difference between permissions and policies: the former controls who can perform stack operations, the latter controls how AWS CloudFormation manages updates to resources in the stack.
Practice: Always practice creating and managing stack policies in AWS CloudFormation to get a full understanding of how they work.
AWS Certified Solutions Architect - Stack policies Example Questions
Test your knowledge of Stack policies
Question 1
Your team manages an Amazon RDS DB instance with AWS CloudFormation. A stack policy denies Update and Delete actions on the DB instance resource to prevent accidental changes. The DB master password is supplied to the stack as a parameter (not via Secrets Manager) and must be rotated monthly. You want to keep the DB instance under CloudFormation control and maintain the stack policy protections. What should you do to update the password each month?
Question 2
Your AWS CloudFormation stack has a Stack Policy that allows all actions on all resources. You need to temporarily protect a specific resource from being updated during a maintenance event. What approach should you use?
Question 3
You are trying to modify the Stack Policy for an existing AWS CloudFormation stack. Your colleague mistakenly added a Stack Policy that denies any action on any resource. What should you do to regain access to the stack?