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

Provided by Rafal Wilinski
The batchWriteItem method allows you to write multiple items in a single request. This can be more efficient than making separate requests to write each item individually. The code example below writes 3 items to tables "Table1" and "Table2".
The batchWriteItem method returns a BatchWriteItemResult object, which includes the UnprocessedItems attribute. This attribute is a map of tables and requests that failed to be completed due to a lack of sufficient provisioned throughput on the tables. The failed requests can be retried using this attribute.
import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.services.dynamodb.model.batchWriteItemRequest; import software.amazon.awssdk.services.dynamodb.model.batchWriteItemResponse; import software.amazon.awssdk.services.dynamodb.model.writeRequest; import java.util.HashMap; import java.util.Map; DynamoDbClient ddb = DynamoDbClient.create(); Map<String, writeRequest> requestItems = new HashMap<>(); Map<String, attributeValue> item1 = new HashMap<>(); item1.put("id", attributeValue.builder().n("101").build()); item1.put("title", attributeValue.builder().s("Book 101 Title").build()); item1.put("info", attributeValue.builder().s("Book 101 Info").build()); requestItems.put("Table1", writeRequest.builder().putRequest(r->r.item(item1)).build()); Map<String, attributeValue> item2 = new HashMap<>(); item2.put("id", attributeValue.builder().n("102").build()); item2.put("title", attributeValue.builder().s("Book 102 Title").build()); item2.put("info", attributeValue.builder().s("Book 102 Info").build()); requestItems.put("Table1", writeRequest.builder().putRequest(r->r.item(item2)).build()); Map<String, attributeValue> item3 = new HashMap<>(); item3.put("id", attributeValue.builder().n("103").build()); item3.put("title", attributeValue.builder().s("Book 103 Title").build()); item3.put("info", attributeValue.builder().s("Book 103 Info").build()); requestItems.put("Table2", writeRequest.builder().putRequest(r->r.item(item3)).build()); batchWriteItemRequest batchWriteItemRequest = batchWriteItemRequest.builder() .requestItems(requestItems) .build(); batchWriteItemResponse result = ddb.batchWriteItem(batchWriteItemRequest);
Similar Code Examples
- Get Item Request in DynamoDB Using Java
- Batch Load Using DynamoDB Mapper
- Delete Expression in DynamoDB Using Java
- Delete Multiple Items in DynamoDB Using Java
- Update Multiple Items in DynamoDB Using Java
- Update Attribute in DynamoDB Using Java
- Query Hash Key Only in DynamoDB Using Java
- Remove with DynamoDB Mapper
- Get All Items from DynamoDB Using Java
- Batch Query in DynamoDB Using Java
- Remove Item in DynamoDB Using Java
- Delete in DynamoDB Using Java
- Insert in DynamoDB Using Java
- Update Item in DynamoDB Using Java
- Batch Update Using DynamoDB Mapper
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today
Product Features
- New in Dynobase 3.0
- Semantic and Vector Search
- Schema Explorer
- Visual JSON Path Filtering
- Visual Item Diff
- MCP Server for AI Tools
- Use SQL with DynamoDB
- Import CSV To DynamoDB
- Import JSON To DynamoDB
- Export DynamoDB To JSON
- Export DynamoDB To S3
- Export DynamoDB To CSV
- DynamoDB Update Item
- DynamoDB Delete All Items
- DynamoDB Delete Item
- DynamoDB Create Table
- DynamoDB Delete Table
- DynamoDB Conditional Update
DynamoDB Tools
DynamoDB Info
© 2026 Dynobase