DynamoDB: BatchGetItem (Guide w/ Code Examples)

Provided by Rafal Wilinski
Last updated: October 23rd, 2026
Use BatchGetCommand with known full primary keys. Results can be unordered or partial; the loop below retries only unprocessed keys with a bounded backoff.
Install @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb, use an ES module on a supported Node.js runtime, and configure an AWS Region and credentials. The examples use an existing Orders table with String keys pk and sk unless an index or timestamp key is described.
import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, BatchGetCommand } from "@aws-sdk/lib-dynamodb"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); let pending = { Orders: { Keys: [ { pk: "CUSTOMER#123", sk: "ORDER#001" }, { pk: "CUSTOMER#456", sk: "ORDER#002" }, ] }, }; for (let attempt = 0; Object.keys(pending).length > 0; attempt++) { if (attempt === 8) throw new Error("Batch read incomplete: persist pending keys for retry"); if (attempt > 0) await new Promise(resolve => setTimeout(resolve, Math.random() * Math.min(5000, 100 * 2 ** attempt))); const result = await ddb.send(new BatchGetCommand({ RequestItems: pending })); for (const item of result.Responses?.Orders ?? []) console.log(item); pending = result.UnprocessedKeys ?? {}; }
Deduplicate keys and split requests at 100 keys. Missing items are omitted. If retries are exhausted, retain pending keys in your application and surface the partial failure.
Reference: AWS BatchGetItem API. For related access patterns, see DynamoDB query examples.
Similar Code Examples
- DynamoDB: Get All Items
- DynamoDB: Query Date Range
- DynamoDB: Query JSON
- DynamoDB: Query Items
- DynamoDB: Delete Table
- DynamoDB: Increment Counter
- DynamoDB: Query Group By
- DynamoDB: Get Multiple Items
- DynamoDB: Query Ends With
- DynamoDB: GetItem
- DynamoDB: Attribute Not Null
- DynamoDB: Get Random Item
- DynamoDB: Get Last 10 Records
- DynamoDB: Query KeyConditionExpression
- DynamoDB: Query Count
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today
Product Features
DynamoDB Tools
- SSH GUI Client
- Chat With Cloud
- MongoDB GUI Client
- AWS Cost Monitoring
- DynamoDB Query Builder
- DynamoDB Code Examples
- DynamoDB Node.js Queries
- DynamoDB JSON Converter
- DynamoDB UUID Generator
- DynamoDB Local Admin GUI
- DynamoDB Pricing Calculator
- DynamoDB Single-Table Design
- Best DynamoDB GUI Clients
- Dynobase vs DynoTable