DynamoDB: Get Multiple Items (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: BatchGetItem
- DynamoDB: Query Group By
- DynamoDB: Query KeyConditionExpression
- DynamoDB: Get Random Item
- DynamoDB: Delete Table
- DynamoDB: Create if Not Exists
- DynamoDB: Get Unique Values
- DynamoDB: Delete Multiple Items in Javascript
- DynamoDB: Bulk Insert
- DynamoDB BatchWriteItem in Typescript
- DynamoDB: Query Items
- DynamoDB: Query Ends With
- DynamoDB: Not Begins With
- DynamoDB: Query Date Range
- DynamoDB: Get Last Inserted Item
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today