dynobase-icon
Dynobase

Remove Item in DynamoDB Using Java (Guide w/ Code Examples)

Rafal Wilinski

Provided by Rafal Wilinski

To delete an item from a DynamoDB table using the AWS SDK for Java, you can use the deleteItem method of the AmazonDynamoDBClient class. This method enables you to delete an item from a table using its primary key values.

import java.util.Map; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.dynamodbv2.model.AttributeValue; import com.amazonaws.services.dynamodbv2.model.DeleteItemRequest; // Replace "tableName" with the name of your DynamoDB table String tableName = "tableName"; // Create a DynamoDB client AmazonDynamoDBClient client = new AmazonDynamoDBClient(); // Define the primary key values for the item you want to delete Map<String, AttributeValue> key = Map.of( "id", new AttributeValue().withN("123"), // primary key attribute"type", new AttributeValue().withS("foo") // sort key attribute ); // Create a request to delete the item DeleteItemRequest request = new DeleteItemRequest() .withTableName(tableName) .withKey(key); // Delete the item from the table client.deleteItem(request);

Better DynamoDB experience.

First 7 days are. No credit card needed.

Product Features

Download
/
Changelog
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
/
Affiliates & Influencers
© 2024 Dynobase
+
Better DynamoDB Experience.
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.