0
0
DynamoDBquery~5 mins

Return values on write in DynamoDB

Choose your learning style9 modes available
Introduction
When you add or change data in a table, you might want to see what was changed or what the old data looked like. Return values on write let you get this information right away.
You want to confirm what data was added or updated in your table.
You need to see the old data before it was changed to compare or log it.
You want to get the new data after an update without making another request.
You want to check if an item existed before you updated or deleted it.
Syntax
DynamoDB
ReturnValues = "NONE" | "ALL_OLD" | "UPDATED_OLD" | "ALL_NEW" | "UPDATED_NEW"
ReturnValues is a parameter you add to write operations like PutItem, UpdateItem, or DeleteItem.
It controls what data DynamoDB sends back after the write.
Examples
No data is returned after the item is added.
DynamoDB
PutItem with ReturnValues = "NONE"
Returns the entire item as it looks after the update.
DynamoDB
UpdateItem with ReturnValues = "ALL_NEW"
Returns the entire item as it was before deletion.
DynamoDB
DeleteItem with ReturnValues = "ALL_OLD"
Sample Program
This updates the Age attribute for user 123 to 30 and returns only the updated attributes.
DynamoDB
UpdateItem {
  TableName: "Users",
  Key: { "UserId": { S: "123" } },
  UpdateExpression: "SET Age = :newAge",
  ExpressionAttributeValues: { ":newAge": { N: "30" } },
  ReturnValues: "UPDATED_NEW"
}
OutputSuccess
Important Notes
If you set ReturnValues to NONE, no data about the write is returned.
ALL_OLD returns the whole item before the write, useful for deletes or overwrites.
UPDATED_NEW returns only the attributes that changed after the update.
Not all write operations support all ReturnValues options.
Summary
ReturnValues lets you get data back from DynamoDB after writing.
Choose the option based on what info you want: old data, new data, or nothing.
It helps reduce extra requests by returning needed data immediately.