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
- Delete Record in DynamoDB Using Java
- Batch Get in DynamoDB Using Java
- GetItem in DynamoDB Using Java
- Delete Table in DynamoDB Using Java
- Remove Item in DynamoDB Using Java
- Query Index in DynamoDB Using Java
- Batch Insert in DynamoDB Using Java
- Remove Attribute in DynamoDB Using Java
- Get All Items from DynamoDB Using Java
- Delete All Items in DynamoDB Using Java
- Delete All Using DynamoDB Mapper
- Batch Save Using DynamoDB Mapper
- Update Expression in DynamoDB Using Java
- Conditional Update in DynamoDB Using Java
- Batch Read in DynamoDB Using Java
Spend less time in the AWS console, use Dynobase.
Try 7-day free trial. No credit card needed.
Product Features
DynamoDB Tools
DynamoDB Info
© 2024 Dynobase