Search in sources :

Example 1 with DeleteItemRequest

use of software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest in project aws-doc-sdk-examples by awsdocs.

the class DeleteItem method deleteDymamoDBItem.

// snippet-start:[dynamodb.java2.delete_item.main]
public static void deleteDymamoDBItem(DynamoDbClient ddb, String tableName, String key, String keyVal) {
    HashMap<String, AttributeValue> keyToGet = new HashMap<String, AttributeValue>();
    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);
    }
}
Also used : AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) HashMap(java.util.HashMap) DeleteItemRequest(software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException)

Aggregations

HashMap (java.util.HashMap)1 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)1 DeleteItemRequest (software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest)1 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)1