Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB - Return which ConditionExpression was false

I am calling PutItem with a ConditionExpression that looks like:

attribute_exists(id) AND object_version = :x

In other words, I only want to update an item if the following conditions are true:

  1. The object needs to exists
  2. My update must be on latest version of the object

Right now, if the check fails, I don't know which condition was false. Is there a way to get information on which conditions were false? Probably not but who knows...

like image 967
surj Avatar asked Feb 13 '16 06:02

surj


1 Answers

Conditional expressions in DynamoDB allow for atomic write operations for DynamoDB objects that is strongly consistent for a single object, even in a distributed system thanks to paxos.

One standard approach is to simply read the object first and perform your above check in your client application code. If one of the conditions doesn't match you know which one was invalid directly without a failed write operation. The reason for having DynamoDB also perform this check is because another application or thread may have modified this object between the check and write. If the write failed then you would read the object again and perform the check again.

Another approach would be to skip the read before the write and just read the object after the failed write to do the check in your code to determine what condition actually failed.

The one or two additional reads against the table are required because you want to know which specific condition failed. This feature is not provided by DynamoDB so you'll have to do the check yourself.

like image 156
JaredHatfield Avatar answered Sep 28 '22 02:09

JaredHatfield