CloudConsole

IAM policy: read and write one DynamoDB table

Updated 17 November 2026 · How we write and check guides

Short answer

Allow the item-level actions your code uses (GetItem, PutItem, UpdateItem, DeleteItem, Query and the batch calls) on the table ARN, and add the table's index ARN (table/orders/index/*) for queries on secondary indexes. Leave out Scan, DeleteTable and UpdateTable unless the app really needs them.

Policy diagram: 2 statement(s); first Allow dynamodb:GetItem, dynamodb:BatchGetItem… on dynamodb: table/orders
The policy on this page drawn statement by statement: who it applies to, the actions, the resources and any condition.

The policy

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadWriteItems",
      "Effect": "Allow",
      "Action": [
        "dynamodb:GetItem",
        "dynamodb:BatchGetItem",
        "dynamodb:Query",
        "dynamodb:PutItem",
        "dynamodb:UpdateItem",
        "dynamodb:DeleteItem",
        "dynamodb:BatchWriteItem",
        "dynamodb:ConditionCheckItem"
      ],
      "Resource": "arn:aws:dynamodb:eu-west-2:123456789012:table/orders"
    },
    {
      "Sid": "QueryIndexes",
      "Effect": "Allow",
      "Action": "dynamodb:Query",
      "Resource": "arn:aws:dynamodb:eu-west-2:123456789012:table/orders/index/*"
    }
  ]
}

What each part covers

  • Reads: GetItem and BatchGetItem for single keys, Query for a partition.
  • Writes: PutItem, UpdateItem, DeleteItem and BatchWriteItem. ConditionCheckItem is only used inside transactions.
  • Transactions have no permission of their own. TransactWriteItems is authorised as the individual put, update, delete and condition-check actions; TransactGetItems as GetItem.
  • QueryIndexes: global and local secondary indexes are separate resources. A Query with IndexName is checked against table/orders/index/<name>, so the table ARN alone isn't enough.

Scan is left out on purpose. It reads the whole table, costs accordingly, and is rarely what request-path code should do. Add it only for jobs that need it.

Attach it

aws iam put-role-policy --role-name orders-api-lambda \
  --policy-name orders-table --policy-document file://orders-table.json

aws iam simulate-principal-policy \
  --policy-source-arn arn:aws:iam::123456789012:role/orders-api-lambda \
  --action-names dynamodb:Query dynamodb:Scan \
  --resource-arns arn:aws:dynamodb:eu-west-2:123456789012:table/orders

The simulator should show allowed for Query and implicitDeny for Scan.

Variations

  • Read-only: keep GetItem, BatchGetItem, Query and DescribeTable.
  • Each user sees only their own items: add "Condition": {"ForAllValues:StringEquals": {"dynamodb:LeadingKeys": ["${aws:PrincipalTag/customer_id}"]}}, so requests may only use partition keys equal to the caller's tag. This is how mobile apps with Cognito identities are commonly scoped.
  • Streams consumer: add dynamodb:DescribeStream, dynamodb:GetRecords, dynamodb:GetShardIterator on table/orders/stream/* and dynamodb:ListStreams.
  • PartiQL: ExecuteStatement is authorised as dynamodb:PartiQLSelect, PartiQLInsert, PartiQLUpdate and PartiQLDelete.

Find every action your code calls

If you're tightening an existing broad policy, look at what the role really does before trimming. With CloudTrail data events enabled for the table, item-level calls appear as events; IAM Access Analyzer can also generate a policy from a role's CloudTrail history. Last-accessed information shows which services a role has used, but not which DynamoDB actions.

aws iam generate-service-last-accessed-details \
  --arn arn:aws:iam::123456789012:role/orders-api-lambda

Common mistakes

  • Index queries denied while table queries work: the /index/* resource is missing.
  • Wrong region or account in the ARN. Table ARNs are regional; a global table needs the ARN for each replica region the app writes to.
  • dynamodb:* on * in production: includes DeleteTable and backup deletion. If you need a safety net, see deny deleting a resource.
  • Customer managed KMS key on the table: also allow kms:Decrypt on it, or reads fail with a KMS access error.

Questions

What is the minimum IAM policy for DynamoDB Query?

dynamodb:Query on the table ARN, and on table/<name>/index/* if you query an index.

Do DynamoDB transactions need a separate permission?

No. Each item in a transaction is checked against the matching item action, such as PutItem or ConditionCheckItem.

When this happens away from your desk

If writes to a table start failing, throttling and access errors look similar from the outside. Checking the table's metrics and the function's logs from your phone tells you which one it is.

About the app → · Download on the App Store

Sources