Reading & Writing Policies

Learn to read a policy line by line, and how AWS decides between Allow and Deny.

1 min read

A policy is a short JSON document. Most of the time you only need four fields:

  • Effect: Allow or Deny.
  • 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:

  1. An explicit Deny anywhere wins. Always.
  2. Otherwise, if something explicitly Allows it, it's allowed.
  3. Otherwise it's denied by default (the implicit deny).
Watch out

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

notesnap-read-policy.json
{
  "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. 1. A user has one policy that allows s3:DeleteObject and another that explicitly denies it. What happens?

  2. 2. What does `"Version": "2012-10-17"` mean in a policy?