Reading & Writing Policies
Learn to read a policy line by line, and how AWS decides between Allow and Deny.
A policy is a short JSON document. Most of the time you only need four fields:
- Effect:
AlloworDeny. - Action: which API calls, e.g.
s3:GetObject. Format:service:Operation. - Resource: which exact thing, as an ARN (Amazon Resource Name).
- Condition (optional): extra rules, like "only from this IP" or "only if MFA was used".
How AWS decides
AWS evaluates every policy that applies to a request, then follows three rules in order:
- An explicit Deny anywhere wins. Always.
- Otherwise, if something explicitly Allows it, it's allowed.
- Otherwise it's denied by default (the implicit deny).
Avoid "Action": "*" and "Resource": "*" together. That says "do anything to everything", which is
effectively admin access. It's fine while experimenting in a sandbox account and dangerous anywhere else.
Try it
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadUploadedNotes",
"Effect": "Allow",
"Action": ["s3:GetObject"],
"Resource": "arn:aws:s3:::notesnap-uploads/*"
},
{
"Sid": "NeverDeleteNotes",
"Effect": "Deny",
"Action": ["s3:DeleteObject"],
"Resource": "arn:aws:s3:::notesnap-uploads/*"
}
]
}Reading it in plain English: "You may read any object inside the notesnap-uploads bucket. You may never
delete objects there, even if some other policy says you can."
"Version": "2012-10-17" is the policy language version, not today's date. Always use exactly this value.
Key takeaways
- Effect, Action, Resource, and optionally Condition: that's 90% of every policy.
- Explicit Deny beats Allow, and anything not allowed is denied by default.
- Scope Resources to specific ARNs instead of using `*`.
Check your understanding
Pick an answer to see the explanation.
1. A user has one policy that allows s3:DeleteObject and another that explicitly denies it. What happens?
2. What does `"Version": "2012-10-17"` mean in a policy?