dynobase-icon
Dynobase

Remove with DynamoDB Mapper (Guide w/ Code Examples)

Rafal Wilinski

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);

Better DynamoDB experience.

Try 7-day free trial. No credit card needed.

Product Features

Download
/
Changelog
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2024 Dynobase
+
Login to the AWS Console less.
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.