Skip to content
IAM Policy Generator

IAM policy example: limit DynamoDB items to the caller, with a least privilege rewrite

Allows a signed-in web identity to read and write only the items in a table whose partition key equals the caller's identity, using the dynamodb:LeadingKeys condition key. Other users' items are out of reach. The original omits any limit on attributes, which the rewrite adds.

Open the workbench ยท All examples

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "OwnItems",
      "Effect": "Allow",
      "Action": [
        "dynamodb:GetItem",
        "dynamodb:PutItem",
        "dynamodb:UpdateItem",
        "dynamodb:DeleteItem",
        "dynamodb:Query"
      ],
      "Resource": "arn:aws:dynamodb:us-east-1:111122223333:table/GameScores",
      "Condition": {
        "ForAllValues:StringEquals": {
          "dynamodb:LeadingKeys": [
            "${www.amazonaws.com:user_id}"
          ]
        }
      }
    }
  ]
}

What it allows

  • Allows five item actions on the GameScores table when every partition key in the request equals the caller's web identity.

What it allows

  1. Allow 5 actions (dynamodb:GetItem, dynamodb:PutItem, dynamodb:UpdateItem, dynamodb:DeleteItem, dynamodb:Query) on arn:aws:dynamodb:us-east-1:111122223333:table/GameScores when dynamodb:LeadingKeys ForAllValues:StringEquals ${www.amazonaws.com:user_id}.

    Action or patternActionsAccess levels
    dynamodb:GetItem1Read 1
    dynamodb:PutItem1Write 1
    dynamodb:UpdateItem1Write 1
    dynamodb:DeleteItem1Write 1
    dynamodb:Query1Read 1

Checks

No flags from the six checks.

Every attribute of the caller's items is readable and writable, including attributes the application never exposes.

Least privilege rewrite

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "OwnItems",
      "Effect": "Allow",
      "Action": [
        "dynamodb:GetItem",
        "dynamodb:PutItem",
        "dynamodb:UpdateItem",
        "dynamodb:DeleteItem",
        "dynamodb:Query"
      ],
      "Resource": "arn:aws:dynamodb:us-east-1:111122223333:table/GameScores",
      "Condition": {
        "ForAllValues:StringEquals": {
          "dynamodb:LeadingKeys": [
            "${www.amazonaws.com:user_id}"
          ],
          "dynamodb:Attributes": [
            "UserId",
            "GameTitle",
            "Wins",
            "Losses"
          ]
        },
        "StringEqualsIfExists": {
          "dynamodb:Select": "SPECIFIC_ATTRIBUTES"
        }
      }
    }
  ]
}

The rewrite adds dynamodb:Attributes so callers touch four named attributes, and requires requests to select specific attributes.

What it allows

  1. Allow 5 actions (dynamodb:GetItem, dynamodb:PutItem, dynamodb:UpdateItem, dynamodb:DeleteItem, dynamodb:Query) on arn:aws:dynamodb:us-east-1:111122223333:table/GameScores when dynamodb:LeadingKeys ForAllValues:StringEquals ${www.amazonaws.com:user_id} and dynamodb:Attributes ForAllValues:StringEquals UserId or GameTitle or Wins or Losses and dynamodb:Select StringEqualsIfExists SPECIFIC_ATTRIBUTES.

    Action or patternActionsAccess levels
    dynamodb:GetItem1Read 1
    dynamodb:PutItem1Write 1
    dynamodb:UpdateItem1Write 1
    dynamodb:DeleteItem1Write 1
    dynamodb:Query1Read 1

Checks

No flags from the six checks.

Sources

  1. Amazon DynamoDB Developer Guide: identity-based policies, read 16 Nov 2026
  2. AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026), read 16 Nov 2026

Last reviewed 16 Nov 2026.