Remove Item in DynamoDB Using Java (Guide w/ Code Examples)
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);
Similar Code Examples
- Update Item in DynamoDB Using Java
- Delete All Items in DynamoDB Using Java
- Batch Read in DynamoDB Using Java
- Get Item Request in DynamoDB Using Java
- Query Date Range in DynamoDB Using Java
- Delete Multiple Items in DynamoDB Using Java
- Update Attribute in DynamoDB Using Java
- Delete in DynamoDB Using Java
- Conditional Update in DynamoDB Using Java
- Update Multiple Items in DynamoDB Using Java
- Get in DynamoDB Using Java
- Update Multiple Attributes in DynamoDB Using Java
- Delete Expression in DynamoDB Using Java
- Query Global Secondary Index in DynamoDB Using Java
- Remove with DynamoDB Mapper
Better DynamoDB experience.
First 7 days are. No credit card needed.
Product Features
DynamoDB Tools
DynamoDB Info
© 2024 Dynobase