DynamoDB: Delete All Items With Partition Key (Guide w/ Code Examples)

Provided by Rafal Wilinski
Last updated: October 23rd, 2026
Query every page for a partition-key value, then delete each full key. This removes an item collection, not the physical DynamoDB partition.
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, QueryCommand, DeleteCommand } from "@aws-sdk/lib-dynamodb"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); let lastKey; do { const page = await ddb.send(new QueryCommand({ TableName: "Orders", KeyConditionExpression: "#pk = :pk", ExpressionAttributeNames: { "#pk": "pk" }, ExpressionAttributeValues: { ":pk": "CUSTOMER#123" }, ExclusiveStartKey: lastKey, })); for (const item of page.Items ?? []) { await ddb.send(new DeleteCommand({ TableName: "Orders", Key: { pk: item.pk, sk: item.sk }, })); } lastKey = page.LastEvaluatedKey; } while (lastKey && Object.keys(lastKey).length > 0);
Use this destructive example only for a controlled purge. Concurrent writes can escape deletion or change items between reading and deleting; stop writers or design conditional deletes.
Reference: AWS DeleteItem API. For related access patterns, see DynamoDB query examples.
Similar Code Examples
- DynamoDB: Get Last 10 Records
- DynamoDB: BatchGetItem
- DynamoDB Get in Typescript
- DynamoDB: Query Group By
- DynamoDB: Not Begins With
- DynamoDB: Get Unique Values
- DynamoDB: Batch Get
- DynamoDB: Query KeyConditionExpression
- DynamoDB: Create if Not Exists
- DynamoDB: Query Date Range
- DynamoDB: Delete Table
- DynamoDB: Get Last Inserted Item
- DynamoDB: Attribute Not Null
- DynamoDB BatchWriteItem in Typescript
- DynamoDB: Like
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