0
0
DynamoDBquery~10 mins

Return values on write in DynamoDB - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Return values on write
Start Write Operation
Perform Write (Put/Update/Delete)
Check ReturnValues Parameter
NONE
Return No
Attributes
End Write Operation
When you write data, you can choose what old or new attribute values to get back by setting ReturnValues.
Execution Sample
DynamoDB
UpdateItem {
  Key: {id: 1},
  UpdateExpression: 'SET age = :newAge',
  ExpressionAttributeValues: {':newAge': 30},
  ReturnValues: 'UPDATED_OLD'
}
This updates the age attribute and returns the old age value before update.
Execution Table
StepActionReturnValuesReturned Data
1Start UpdateItemN/ANo data returned yet
2Apply UpdateExpressionUPDATED_OLDOld attribute values before update
3Return responseUPDATED_OLD{"age": 25}
4End operationN/AUpdate complete, returned old age
💡 Update applied and old attribute values returned as per ReturnValues = UPDATED_OLD
Variable Tracker
VariableStartAfter Step 2After Step 3Final
age2530 (updated)25 (returned)30 (stored)
ReturnValuesN/AUPDATED_OLDUPDATED_OLDUPDATED_OLD
Key Moments - 2 Insights
Why do we get old attribute values back instead of new ones?
Because ReturnValues is set to UPDATED_OLD, DynamoDB returns the attribute values before the update, as shown in execution_table step 3.
What happens if ReturnValues is NONE?
No attribute values are returned after the write, so the response contains no data, unlike the UPDATED_OLD case in step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is returned at step 3?
AThe new attribute values after update
BThe old attribute values before update
CNo attribute values
DAn error message
💡 Hint
Check the 'Returned Data' column at step 3 in execution_table
At which step is the update applied to the attribute 'age'?
AStep 2
BStep 1
CStep 3
DStep 4
💡 Hint
Look at the 'Action' column in execution_table where update happens
If ReturnValues was set to NONE, what would change in the execution_table?
AReturned Data at step 3 would show old values
BReturned Data at step 3 would show new values
CReturned Data at step 3 would be empty
DThe update would not happen
💡 Hint
ReturnValues NONE means no data returned after write
Concept Snapshot
ReturnValues controls what data DynamoDB returns after a write.
Options include NONE (no data), ALL_OLD (all old attributes), UPDATED_OLD (only updated old attributes), ALL_NEW (all new attributes), UPDATED_NEW (only updated new attributes).
Set ReturnValues in your write request to get desired feedback.
Useful for confirming changes or retrieving previous data.
Full Transcript
When you perform a write operation in DynamoDB, such as UpdateItem, you can specify the ReturnValues parameter to control what attribute data is returned. The options include NONE, ALL_OLD, UPDATED_OLD, ALL_NEW, and UPDATED_NEW. For example, if you set ReturnValues to UPDATED_OLD, DynamoDB returns only the attribute values that were updated, but before the update. The execution flow starts with the write request, applies the update, checks the ReturnValues setting, and returns the requested data. This helps you confirm what changed or retrieve previous values without a separate read. If ReturnValues is NONE, no attribute data is returned. Understanding this helps you write efficient and clear DynamoDB operations.