2

Is there a way to make a Dynamodb Update return Old and New values?

something like:

updateItemSpec
    .withPrimaryKey("id", id)
    .withUpdateExpression(myUpdateExpression)
    .withNameMap(nameMap)
    .withValueMap(valueMap)
    .withReturnValues("UPDATED_NEW, UPDATED_OLD");   

2 Answers 2

4

There isn't.

It should be easy for you to simulate this by returning UPDATED_OLD. You already have the new values as you set them in the update, so get the updated old values, and use that to extract your new values from your value map.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks... But, actually I do not have the new value. because myUpdateExpression is something like "SET myValue = myValue + incrementValue". That's why I would like dynamo to return OLD and NEW values;
I see. But in that case you still have what the value was before the update, and you will know what the increment is, so you can calculate the new value surely?
You're right I get the new value from Dynamo, then I calculate the old Value... Thanks
0

Depending on where you want to use the data, if you don't need it in the body of code where you update a DynamoDB record, you can capture table activity using DynamoDB streams. You can configure an AWS lambda trigger on the table so it invokes the lambda when a specified event occurs, passing this event (in our case, the stream) to the lambda. From this, depending on how you have set up the stream, you can access the old and new versions of the record.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.