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 Attribute in DynamoDB Using Java
- Batch Write Item in DynamoDB Using Java
- Remove with DynamoDB Mapper
- Query Hash Key Only in DynamoDB Using Java
- Batch Get in DynamoDB Using Java
- Batch Query in DynamoDB Using Java
- Query Global Secondary Index in DynamoDB Using Java
- Batch Save Using DynamoDB Mapper
- Batch Insert in DynamoDB Using Java
- Delete Table in DynamoDB Using Java
- Batch Update Using DynamoDB Mapper
- Query Date Range in DynamoDB Using Java
- Batch Write Using DynamoDB Mapper
- Delete Expression in DynamoDB Using Java
- Delete by Hashkey Using DynamoDB Mapper
Tired of AWS Console? Try Dynobase.
Start your 7-day free trial today
Product Features
DynamoDB Tools
DynamoDB Info
© 2024 Dynobase