Remove Item in DynamoDB Using Java (Guide w/ Code Examples)
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
- Get Multiple Items in DynamoDB Using Java
- Batch Put Item in DynamoDB Using Java
- Batch Insert in DynamoDB Using Java
- Batch Save Using DynamoDB Mapper
- Batch Update Using DynamoDB Mapper
- Update Expression in DynamoDB Using Java
- Batch Load Using DynamoDB Mapper
- Delete Record in DynamoDB Using Java
- Get All Items from DynamoDB Using Java
- Conditional Update in DynamoDB Using Java
- Remove Attribute in DynamoDB Using Java
- Batch Delete Using DynamoDB Mapper
- Query Date Range in DynamoDB Using Java
- Delete in DynamoDB Using Java
- Delete Expression in DynamoDB Using Java
Dynobase is a Professional GUI Client for DynamoDB
First 7 days are on us. No strings attached.
Product Features
DynamoDB Tools
DynamoDB Info
© 2023 Dynobase