Posted: 10/Jan/2024
The DynamoDB UpdateItem
operation is quite flexible. In addition to using many types of operations, you can:
- Use multiple update expressions in a single statement
- Get the item attributes as they appear before or after they are successfully updated
- Understand which item attributes failed the condition check (no additional cost)
- Retrieve the consumed Write Capacity Units (WCU)
Here is an example (using AWS Go SDK v2):
resp, err = client.UpdateItem(context.Background(), &dynamodb.UpdateItemInput{
TableName: aws.String(tableName),
Key: map[string]types.AttributeValue{
"email": &types.AttributeValueMemberS{Value: email},
},
UpdateExpression: aws.String("SET last_name = :ln REMOVE category"),
ExpressionAttributeValues: map[string]types.AttributeValue{
":ln": &types.AttributeValueMemberS{
Value: lastName,
},
},
ReturnValues: types.ReturnValueAllOld,
ReturnValuesOnConditionCheckFailure: types.ReturnValuesOnConditionCheckFailureAllOld,
ReturnConsumedCapacity: types.ReturnConsumedCapacityTotal,
}
Recommended reading:
Top comments (0)