Delete Record in DynamoDB Using Java (Guide w/ Code Examples)
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 Insert in DynamoDB Using Java
- Insert in DynamoDB Using Java
- Batch Put Item in DynamoDB Using Java
- Get Item Request in DynamoDB Using Java
- Batch Query in DynamoDB Using Java
- Delete in DynamoDB Using Java
- Query Date Range in DynamoDB Using Java
- Batch Read in DynamoDB Using Java
- Remove Item in DynamoDB Using Java
- Batch Update Using DynamoDB Mapper
- Delete by Hashkey Using DynamoDB Mapper
- Delete Multiple Items in DynamoDB Using Java
- Update Item in DynamoDB Using Java
- Delete Expression in DynamoDB Using Java
- GetItem 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
© 2025 Dynobase