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 Hash Key Only in DynamoDB Using Java
- Insert in DynamoDB Using Java
- Batch Load Using DynamoDB Mapper
- Delete Multiple Items in DynamoDB Using Java
- Batch Read in DynamoDB Using Java
- Get All Items from DynamoDB Using Java
- Update Attribute in DynamoDB Using Java
- Delete All Items in DynamoDB Using Java
- Delete All Using DynamoDB Mapper
- Query Index in DynamoDB Using Java
- Remove Attribute in DynamoDB Using Java
- Update Expression in DynamoDB Using Java
- Batch Write Using DynamoDB Mapper
- Batch Put Item in DynamoDB Using Java
- Get Item Request in DynamoDB Using Java
Spend less time in the AWS console, use Dynobase.
First 7 days are. No credit card needed.
Product Features
DynamoDB Tools
DynamoDB Info
© 2024 Dynobase