DynamoDB BatchGetItem with the AWS CLI

aws dynamodb batch-get-item fetches up to 100 items by primary key in a single command (16 MB max). The keys go in --request-items as a map of table → keys in DynamoDB JSON — and you must check UnprocessedKeys in the output, because a batch can legally return only part of what you asked for.

Code

aws dynamodb batch-get-item \
  --request-items '{
    "Music": {
      "Keys": [
        {"Artist": {"S": "Arturo Sandoval"}, "SongTitle": {"S": "Cubano Chant"}},
        {"Artist": {"S": "Arturo Sandoval"}, "SongTitle": {"S": "A Mis Abuelos"}},
        {"Artist": {"S": "Ella Fitzgerald"}, "SongTitle": {"S": "Misty"}}
      ]
    }
  }'

The output maps each table to the items found, plus any leftovers:

{
    "Responses": {
        "Music": [
            {"Artist": {"S": "Arturo Sandoval"}, "SongTitle": {"S": "Cubano Chant"}, ...}
        ]
    },
    "UnprocessedKeys": {}
}

Explanation

  • --request-items — a map of table name → {"Keys": [...]}; one command can span multiple tables. Every key must be the full primary key (partition + sort for a composite key). More than 100 keys, or the same key twice, fails with a ValidationException.
  • Responses — items come back in no particular order, and keys that don't exist simply don't appear — match results to requests by their key attributes.
  • UnprocessedKeys — unlike query/scan, the CLI does not auto-retry a partial batch (it's not a pagination token). If the map is non-empty — throttling, a >16 MB response — re-run the command with that exact map as --request-items (it's already in the right form), backing off between attempts.
  • Per table you can add "ProjectionExpression": "..." (with "ExpressionAttributeNames") to fetch only some attributes, and "ConsistentRead": true for strongly consistent reads — batch reads are eventually consistent by default.
  • Tip: for more than a few keys, keep the map in a file and pass --request-items file://keys.json.

Do it visually

Hand-writing nested DynamoDB JSON in shell quotes is error-prone. The DynamoDB Expression Builder builds typed key/value maps and copies ready-to-run CLI commands.

To fetch and inspect items across tables in a GUI — no JSON escaping, no re-run bookkeeping — download DynoTable.

References

Last verified 2026-07-13 against the official AWS documentation linked above.

Work with DynamoDB without the Console

DynoTable is a fast desktop client for DynamoDB — browse tables, run SQL-style queries, and edit items locally.