In DynamoDB it is possible to set a ConditionExpression
on a single attribute like this:
ConditionExpression: 'attribute_exists(user_id)'
If this ConditionExpression is defined on an update, and the user_id does not exist, the ConditionExpression evaluates to false and returns an exception:
message: 'The conditional request failed',
code: 'ConditionalCheckFailedException',
requestId: 'KPFMA7S5P110FCOMLPMKP15UDBVV4KQNSO6AEMVJF66Q9ASUAAJG',
statusCode: 400
Whilst there is only one condition to evaluate everything is clear, but when multiple conditions are specified, DynamoDB does not report which condition failed:
ConditionExpression: 'attribute_exists(user_id) and iq = 85'
then exception is the same as above, thus it's impossible to say what exactly caused the condition evaluated to false.
Is there a way (even hacky one) to get more details out of that exception information?
Unfortunately DynamoDB will not provide any additional details - it will not tell you which part of the ConditionExpression failed.
The only thing I can think of doing is to execute a query immediately before or after you run the update expression, compare the necessary attributes, and log the result.
If you ran the query before the update, you could execute or skip the update as required. In effect you would be implementing your own condition handling.
Alternatively you could execute the query as part of a catch block after your update try block, such that the query would only run if the update failed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With