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

Facts read 16 Nov 2026. Page reviewed 16 Nov 2026.

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.

```json
{
  "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.

- Allows 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}.

Checks:
- No flags.

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

## Least privilege rewrite

```json
{
  "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.

- Allows 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.

Checks:
- No flags.

- [Paste it into the workbench](/)
- [Every DynamoDB action and its access level](/actions/dynamodb/)

## Related pages

- [IAM policy example: read a DynamoDB stream](/examples/dynamodb-read-streams-for-consumer/)
- [IAM policy example: let users manage their own MFA device](/examples/iam-manage-own-mfa-device/)
- [IAM policy example: change your own password and keys](/examples/iam-manage-own-credentials/)
- [All of them](/examples/)

## Sources

- Amazon DynamoDB Developer Guide: identity-based policies: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/using-identity-based-policies.html (read 16 Nov 2026)
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026): https://docs.aws.amazon.com/service-authorization/latest/reference/service-reference.html (read 16 Nov 2026)

Last reviewed 16 Nov 2026. Canonical: https://iampolicygenerator.com/examples/dynamodb-leading-keys-per-user/

This site is not affiliated with Amazon Web Services. AWS service and product names are used only to describe AWS services.
