Batch Write Item in DynamoDB Using Java (Guide w/ Code Examples)

Provided by Rafal Wilinski
Last updated: October 23rd, 2026
BatchWriteItem puts or deletes several complete items in one request. This example writes two key-only sample items and retries unprocessed writes with bounded exponential backoff and jitter.
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().putRequest(PutRequest.builder().item(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(); } } } }
A put replaces the entire existing item with that key. Batch writes cannot attach conditions or update individual attributes. Split larger inputs into groups of at most 25 operations and stay below the request-size limit.
Reference: AWS BatchWriteItem API. For related access patterns, see DynamoDB query examples.
Similar Code Examples
- Query Index in DynamoDB Using Java
- Delete All Items in DynamoDB Using Java
- Query Global Secondary Index in DynamoDB Using Java
- Insert in DynamoDB Using Java
- Remove Attribute in DynamoDB Using Java
- Conditional Update in DynamoDB Using Java
- GetItem in DynamoDB Using Java
- Delete by Hashkey Using DynamoDB Mapper
- Update Item in DynamoDB Using Java
- Batch Load Using DynamoDB Mapper
- Update Expression in DynamoDB Using Java
- Batch Insert in DynamoDB Using Java
- Batch Update Using DynamoDB Mapper
- Delete Multiple Items in DynamoDB Using Java
- Remove Item in DynamoDB Using Java
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