Remove with DynamoDB Mapper (Guide w/ Code Examples)

Provided by Rafal Wilinski
You can use the method to remove an item from a table using the DynamoDB Mapper. This method takes an object representing the item to delete and deletes it from the table.
DynamoDBMapper mapper = new DynamoDBMapper(client); Item item = new Item(); item.setId(123); // Set the primary key value // Delete the item mapper.delete(item);
The delete method only works for tables that have a single primary key attribute. If your table has a composite primary key (a primary key made up of multiple attributes), you will need to use the delete method of the AmazonDynamoDB client, which takes a DeleteItemRequest object as a parameter.
Map<String, AttributeValue> key = new HashMap<>(); key.put("attr1", new AttributeValue().withS("value1")); key.put("attr2", new AttributeValue().withN("123")); DeleteItemRequest deleteItemRequest = new DeleteItemRequest() .withTableName("myTable") .withKey(key); client.deleteItem(deleteItemRequest);
Similar Code Examples
- Query Date Range in DynamoDB Using Java
- Delete All Items in DynamoDB Using Java
- Batch Load Using DynamoDB Mapper
- Update Attribute in DynamoDB Using Java
- Update Item in DynamoDB Using Java
- Delete Expression in DynamoDB Using Java
- Conditional Update in DynamoDB Using Java
- GetItem in DynamoDB Using Java
- Batch Get in DynamoDB Using Java
- Batch Delete Using DynamoDB Mapper
- Delete Multiple Items in DynamoDB Using Java
- Get Multiple Items in DynamoDB Using Java
- Query Index in DynamoDB Using Java
- Get All Items from DynamoDB Using Java
- Batch Update Using DynamoDB Mapper
Spend less time in the AWS console, use Dynobase.
First 7 days are on us. No strings attached.
Product Features
DynamoDB Tools
DynamoDB Info
© 2025 Dynobase