Update Multiple Attributes in DynamoDB Using Java (Guide w/ Code Examples)

Provided by Rafal Wilinski
Last updated: October 23rd, 2026
One UpdateItem request can change several attributes atomically on the same item. Alias attribute names and pass values separately; this example preserves all other attributes.
This example uses Java 17+ and the software.amazon.awssdk:dynamodb SDK 2.x dependency. Configure an AWS Region and credentials through your usual AWS profile or runtime role. The Orders table has String keys pk and sk; adapt the table and keys to your schema.
import java.util.*; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.*; public class Example { static AttributeValue s(String value) { return AttributeValue.builder().s(value).build(); } static Map<String, AttributeValue> key(String order) { return Map.of("pk", s("CUSTOMER#123"), "sk", s(order)); } public static void main(String[] args) throws InterruptedException { try (DynamoDbClient ddb = DynamoDbClient.create()) { UpdateItemResponse response = ddb.updateItem(UpdateItemRequest.builder() .tableName("Orders").key(key("ORDER#001")) .updateExpression("SET #status = :status, #carrier = :carrier") .conditionExpression("attribute_exists(pk)") .expressionAttributeNames(Map.of("#status", "status", "#carrier", "carrier")) .expressionAttributeValues(Map.of(":status", s("SHIPPED"), ":carrier", s("ExampleCarrier"))) .returnValues(ReturnValue.ALL_NEW).build()); System.out.println(response.attributes()); } } }
Reference: AWS UpdateItem API. For related access patterns, see DynamoDB query examples.
Similar Code Examples
- Get All Items from DynamoDB Using Java
- Batch Write Item in DynamoDB Using Java
- Delete Multiple Items in DynamoDB Using Java
- Query Global Secondary Index in DynamoDB Using Java
- Batch Load Using DynamoDB Mapper
- Delete in DynamoDB Using Java
- GetItem in DynamoDB Using Java
- Batch Get in DynamoDB Using Java
- Query Date Range in DynamoDB Using Java
- Query Hash Key Only in DynamoDB Using Java
- Remove Attribute in DynamoDB Using Java
- Remove with DynamoDB Mapper
- Delete by Hashkey Using DynamoDB Mapper
- Remove Item in DynamoDB Using Java
- Batch Write Using DynamoDB Mapper
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today
Product Features
DynamoDB Tools
- SSH GUI Client
- Chat With Cloud
- MongoDB GUI Client
- AWS Cost Monitoring
- DynamoDB Query Builder
- DynamoDB Code Examples
- DynamoDB Node.js Queries
- DynamoDB JSON Converter
- DynamoDB UUID Generator
- DynamoDB Local Admin GUI
- DynamoDB Pricing Calculator
- DynamoDB Single-Table Design
- Best DynamoDB GUI Clients
- Dynobase vs DynoTable
DynamoDB Info
© 2026 Dynobase