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

Provided by Rafal Wilinski
To delete multiple items from a DynamoDB table in Java, you can use the batchWriteItem
method of the AmazonDynamoDBClient
class. This method lets you delete up to 25 items in a single request. The example below demonstrates how to use the batchWriteItem
method to delete items from a table called "myTable".
import java.util.ArrayList; import java.util.List; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.dynamodbv2.model.AttributeValue; import com.amazonaws.services.dynamodbv2.model.DeleteRequest; import com.amazonaws.services.dynamodbv2.model.WriteRequest; // Replace "tableName" with the name of your DynamoDB table String tableName = "tableName"; // Create a DynamoDB client AmazonDynamoDBClient client = new AmazonDynamoDBClient(); // Create a list of delete requests List<WriteRequest> requests = new ArrayList<>(); // Add delete requests to the list for (int i = 0; i < 25; i++) { AttributeValue value = new AttributeValue().withN(Integer.toString(i)); DeleteRequest request = new DeleteRequest().withKey(Map.of("id", value)); requests.add(new WriteRequest().withDeleteRequest(request)); } // Delete the items from the table client.batchWriteItem(Map.of(tableName, requests));
Similar Code Examples
- Remove Item in DynamoDB Using Java
- Batch Write Using DynamoDB Mapper
- Delete Table in DynamoDB Using Java
- Get All Items from DynamoDB Using Java
- Query Date Range in DynamoDB Using Java
- GetItem in DynamoDB Using Java
- Update Expression in DynamoDB Using Java
- Query Hash Key Only in DynamoDB Using Java
- Batch Read in DynamoDB Using Java
- Update Multiple Items in DynamoDB Using Java
- Batch Query in DynamoDB Using Java
- Query Index in DynamoDB Using Java
- Delete All Items in DynamoDB Using Java
- Batch Get in DynamoDB Using Java
- Delete Expression in DynamoDB Using Java
Tired of switching accounts and regions? Use Dynobase.
Try 7-day free trial. No credit card needed.
Product Features
DynamoDB Tools
DynamoDB Info
© 2025 Dynobase