Update Item in DynamoDB Using Java (Guide w/ Code Examples)
![Rafal Wilinski](https://pbs.twimg.com/profile_images/1390706809548197895/SVCKpLNE_400x400.png)
Provided by Rafal Wilinski
The following example shows how to update an item in a DynamoDB table using the AmazonDynamoDB
interface and the latest version of the AWS SDK, the DynamoDbClient
class is used to create an instance of the DynamoDB client, and the updateItem
method of that client is used to update an item in a table. In the updateItemRequest
, we provide the table name, primary key, and attributeUpdates
, with the action that should be performed on each attribute.
import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.services.dynamodb.model.updateItemRequest; import software.amazon.awssdk.services.dynamodb.model.updateItemResponse; import java.util.HashMap; import java.util.Map; DynamoDbClient ddb = DynamoDbClient.create(); Map<String, attributeValue> key = new HashMap<String, attributeValue>(); key.put("internalKEY", attributeValue.builder().s("111").build()); // primary key Map<String, attributeValueUpdate> updateValues = new HashMap<String, attributeValueUpdate>(); updateValues.put("Make", attributeValueUpdate.builder().value(attributeValue.builder().ss("Make1","Make2").build()).action("ADD").build()); updateValues.put("Price", attributeValueUpdate.builder().value(attributeValue.builder().n("1").build()).action("PUT").build()); updateItemRequest updateItemRequest = updateItemRequest.builder() .tableName("Product") .key(key) .attributeUpdates(updateValues) .build(); updateItemResponse updateItemResponse = ddb.updateItem(updateItemRequest);
Similar Code Examples
- Batch Read in DynamoDB Using Java
- Batch Save Using DynamoDB Mapper
- Update Multiple Attributes in DynamoDB Using Java
- Insert in DynamoDB Using Java
- Batch Delete Using DynamoDB Mapper
- Query Date Range in DynamoDB Using Java
- Delete All Using DynamoDB Mapper
- Batch Update Using DynamoDB Mapper
- Remove with DynamoDB Mapper
- Delete Record in DynamoDB Using Java
- Delete Multiple Items in DynamoDB Using Java
- Query Global Secondary Index in DynamoDB Using Java
- Delete by Hashkey Using DynamoDB Mapper
- GetItem in DynamoDB Using Java
- Remove Attribute in DynamoDB Using Java
Tired of AWS Console? Try Dynobase.
First 7 days are. No credit card needed.
Product Features
DynamoDB Tools
DynamoDB Info
© 2024 Dynobase