Delete Record in DynamoDB Using Java (Guide w/ Code Examples)
![Rafal Wilinski](https://pbs.twimg.com/profile_images/1390706809548197895/SVCKpLNE_400x400.png)
Provided by Rafal Wilinski
In DynamoDB, the item key and table name are all needed to delete an item. Additionally, it is specifically instructed to use a conditional expression, which will be required to prevent deleting the incorrect items.
public static void deleteDymamoDBItem(DynamoDbClient ddb, String tableName, String key, String keyVal) { HashMap<String,AttributeValue> keyToGet = new HashMap<>(); keyToGet.put(key, AttributeValue.builder() .s(keyVal) .build()); DeleteItemRequest deleteReq = DeleteItemRequest.builder() .tableName(tableName) .key(keyToGet) .build(); try { ddb.deleteItem(deleteReq); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } }
Similar Code Examples
- Batch Write Item in DynamoDB Using Java
- Get All Items from DynamoDB Using Java
- Query Index in DynamoDB Using Java
- Batch Get in DynamoDB Using Java
- Get in DynamoDB Using Java
- Delete All Using DynamoDB Mapper
- Batch Insert in DynamoDB Using Java
- Batch Write Using DynamoDB Mapper
- Update Expression in DynamoDB Using Java
- Get Item Request in DynamoDB Using Java
- Delete Multiple Items in DynamoDB Using Java
- Remove with DynamoDB Mapper
- Delete by Hashkey Using DynamoDB Mapper
- Delete Expression in DynamoDB Using Java
- Delete Table in DynamoDB Using Java
Dynobase is a Professional GUI Client for DynamoDB
Try 7-day free trial. No strings attached.
Product Features
DynamoDB Tools
DynamoDB Info
© 2024 Dynobase