DynamoDB: Delete Multiple Items in Javascript (Guide w/ Code Examples)

Provided by Rafal Wilinski
Last updated: October 23rd, 2026
BatchWriteCommand can delete a set of known full primary keys. Each delete is atomic, but the batch is not; retry UnprocessedItems and retain failed work when retries are exhausted.
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, BatchWriteCommand } from "@aws-sdk/lib-dynamodb"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const writes = ["ORDER#001", "ORDER#002"].map(sk => ({ DeleteRequest: { Key: { pk: "CUSTOMER#123", sk } }, })); let pending = { Orders: writes }; for (let attempt = 0; Object.keys(pending).length > 0; attempt++) { if (attempt === 8) throw new Error("Batch write incomplete: persist pending writes 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 BatchWriteCommand({ RequestItems: pending })); pending = result.UnprocessedItems ?? {}; }
Limit each batch to 25 operations. Use conditional DeleteCommand requests instead when an item must still match an expected version or state.
Reference: AWS BatchWriteItem API. For related access patterns, see DynamoDB query examples.
Similar Code Examples
- DynamoDB: Create if Not Exists
- DynamoDB: Not Begins With
- DynamoDB: Query Greater Than
- DynamoDB Get in Typescript
- DynamoDB: Query Global Secondary Index in Nodejs
- DynamoDB: Get All Items
- DynamoDB: Query Items
- DynamoDB: Delete Table
- DynamoDB: Bulk Insert
- DynamoDB: Attribute Not Null
- DynamoDB: GetItem
- DynamoDB: Query KeyConditionExpression
- DynamoDB: Query Ends With
- DynamoDB: Get Last Inserted Item
- DynamoDB: BatchGetItem
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