Skip to the workspace
Pebellslearn by building
IAM — Who May Do What  ›  Lesson

IAM Policies

Policies 16 minAn IAM policy is a JSON document of statements that allow or deny actions on resources, and AWS evaluates them so that an explicit deny beats any allow and anything not allowed is denied.

aws / IAM Policies

Explore each scene at your own pace.

01 · The rule

The rule

IAM Policies

Inkwell's developers need to upload book covers to the inkwell-covers bucket and read them back. Last month someone deleted two hundred covers by mistake, so this time deleting must be impossible. Groups say who; policies say what exactly they may do.

The rule

Deny wins; then allow; otherwise, no.

A policy is a JSON document of statements:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:GetObject", "s3:PutObject"],
      "Resource": "arn:aws:s3:::inkwell-covers/*"
    },
    {
      "Effect": "Deny",
      "Action": "s3:DeleteObject",
      "Resource": "arn:aws:s3:::inkwell-covers/*"
    }
  ]
}
  • Effect: Allow or Deny.
  • Action: API operations, written service:Operation. Wildcards work: s3:* means every S3 action.
  • Resource: which things, named by ARN (Amazon Resource Name). arn:aws:s3:::inkwell-covers is the bucket; arn:aws:s3:::inkwell-covers/* is every object inside it.
  • Condition (optional): extra tests, such as requiring MFA or a source IP range.
  • Version is always "2012-10-17", the current policy language, not today's date.

When a request arrives, AWS gathers every policy that applies and decides in a fixed order:

  1. Any explicit Deny that matches → denied, no matter what else says.
  2. Otherwise, any Allow that matches → allowed.
  3. Otherwise → denied. This default is called the implicit deny.

Policies attached to users, groups and roles are identity-based. Policies attached to a resource, such as an S3 bucket policy, are resource-based and name a Principal, the who. You will write one of those in the S3 section.

Policies also come in two packagings. Managed policies stand alone and can be attached to many identities: AWS publishes ready-made ones such as ReadOnlyAccess, and you can write your own. Inline policies are embedded in a single identity and are deleted with it. Prefer your own managed policies that grant only the actions the job needs: the principle of least privilege.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.