Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get more details out of a `ConditionalCheckFailedException` in AWS DynamoDB?

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?

like image 510
aring Avatar asked Jan 28 '23 20:01

aring


1 Answers

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.

like image 54
F_SO_K Avatar answered Feb 05 '23 18:02

F_SO_K