0
0
DynamoDBquery~10 mins

Multiple actions in one update in DynamoDB - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Multiple actions in one update
Start Update Request
Parse Update Expression
Identify Actions: SET, REMOVE, ADD, DELETE
Apply SET actions
Apply REMOVE actions
Apply ADD actions
Apply DELETE actions
Save Updated Item
Return Updated Attributes
The update request is parsed to identify multiple actions, which are applied in order: SET, REMOVE, ADD, DELETE, then the item is saved and updated attributes returned.
Execution Sample
DynamoDB
UpdateItem {
  Key: {id: "123"},
  UpdateExpression: "SET age = age + :inc REMOVE nickname ADD points :pts",
  ExpressionAttributeValues: {":inc": 1, ":pts": 10}
}
This update increases age by 1, removes nickname attribute, and adds 10 to points in one request.
Execution Table
StepAction TypeAttributeOperationValueResulting Item State
1Parse Update Expression---{"id":"123", "age": 30, "nickname": "Sam", "points": 50}
2SETageage + :inc1{"id":"123", "age": 31, "nickname": "Sam", "points": 50}
3REMOVEnicknameremove attribute-{"id":"123", "age": 31, "points": 50}
4ADDpointspoints + :pts10{"id":"123", "age": 31, "points": 60}
5Save Item---{"id":"123", "age": 31, "points": 60}
6Return Updated Attributes---{"age": 31, "points": 60}
💡 All update actions applied; item saved with new attribute values.
Variable Tracker
VariableStartAfter SETAfter REMOVEAfter ADDFinal
age3031313131
nickname"Sam""Sam"nullnullnull
points5050506060
Key Moments - 3 Insights
Why does the REMOVE action delete the nickname attribute?
Because in the execution_table row 3, REMOVE action explicitly removes the nickname attribute, changing its value to null (absent) in the item state.
How does the ADD action affect the points attribute?
As shown in execution_table row 4, ADD increases points by the value 10, changing points from 50 to 60.
Why is the SET action applied before REMOVE and ADD?
The update expression actions are applied in a fixed order: SET first, then REMOVE, then ADD, ensuring predictable updates as seen in the execution_table steps 2, 3, and 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of age after the SET action?
A31
B30
C32
Dnull
💡 Hint
Check the 'After SET' column in variable_tracker and row 2 in execution_table.
At which step is the nickname attribute removed from the item?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look at the 'Action Type' and 'Attribute' columns in execution_table.
If the ADD action was omitted, what would be the final value of points?
A60
B10
C50
Dnull
💡 Hint
Refer to variable_tracker and note points value before and after ADD action.
Concept Snapshot
UpdateItem in DynamoDB can perform multiple actions in one request.
Actions include SET (change or add attributes), REMOVE (delete attributes), ADD (increment numbers or add to sets), DELETE (remove from sets).
Actions are applied in order: SET, REMOVE, ADD, DELETE.
Use ExpressionAttributeValues for dynamic values.
The updated item is saved and optionally returned.
Full Transcript
This visual execution shows how DynamoDB processes multiple actions in one UpdateItem request. First, the update expression is parsed to identify actions: SET, REMOVE, ADD, and DELETE. Then, each action is applied in order. For example, SET updates or adds attributes, REMOVE deletes attributes, ADD increments numeric attributes or adds to sets, and DELETE removes from sets. The item state changes step-by-step, reflecting each action. Finally, the updated item is saved and the requested attributes are returned. This process ensures multiple changes happen atomically in one update call.