dynobase-icon
Dynobase

Delete Multiple Items in DynamoDB Using Java (Guide w/ Code Examples)

Rafal Wilinski

Provided by Rafal Wilinski

Last updated: October 23rd, 2026

Use BatchWriteItem with DeleteRequest entries to delete items whose full keys you already know. Retry only the returned UnprocessedItems; the whole batch is not atomic.

This example uses Java 17+ and the software.amazon.awssdk:dynamodb SDK 2.x dependency. Configure an AWS Region and credentials through your usual AWS profile or runtime role. The Orders table has String keys pk and sk; adapt the table and keys to your schema.

import java.util.*; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.*; public class Example { static AttributeValue s(String value) { return AttributeValue.builder().s(value).build(); } static Map<String, AttributeValue> key(String order) { return Map.of("pk", s("CUSTOMER#123"), "sk", s(order)); } public static void main(String[] args) throws InterruptedException { try (DynamoDbClient ddb = DynamoDbClient.create()) { List<WriteRequest> writes = new ArrayList<>(); for (String order : List.of("ORDER#001", "ORDER#002")) { writes.add(WriteRequest.builder().deleteRequest(DeleteRequest.builder().key(key(order)).build()).build()); } Map<String, List<WriteRequest>> pending = Map.of("Orders", writes); for (int attempt = 0; !pending.isEmpty(); attempt++) { if (attempt == 8) throw new IllegalStateException("Unprocessed writes: " + pending); if (attempt > 0) Thread.sleep((long) (Math.random() * Math.min(5000L, 100L << attempt))); pending = ddb.batchWriteItem(BatchWriteItemRequest.builder() .requestItems(pending).build()).unprocessedItems(); } } } }

Each batch supports at most 25 put/delete operations. Batch deletes cannot use conditions; use DeleteItem or transactions if deletion depends on the current item state.

Reference: AWS BatchWriteItem API. For related access patterns, see DynamoDB query examples.

Dynobase is a Professional GUI Client for DynamoDB

Start your 7-day free trial today

Product Features

Download
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2026 Dynobase
+
Still using AWS DynamoDB Console?
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.