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 aValidationException.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— unlikequery/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": truefor 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.
Related examples
- DynamoDB BatchGetItem in Node.js — the same batch read with AWS SDK v3.
- DynamoDB BatchGetItem in Python — the same batch read with boto3.
- DynamoDB GetItem with the AWS CLI — the single-item read this batches.
- Batch operations in DynamoDB — limits, partial failure, and when batching pays off.
- "Too many items requested for the BatchGetItem call" — more than 100 keys in one request.
- "Provided list of item keys contains duplicates" — the same key twice in one batch.
References
- BatchGetItem — Amazon DynamoDB API Reference
- batch-get-item — AWS CLI Command Reference
- Error handling with DynamoDB — Amazon DynamoDB Developer Guide
Last verified 2026-07-13 against the official AWS documentation linked above.