DynamoDB Nodejs ConditionalExpresion attribute_exists - Error in validation

698 views Asked by At

i am programming in nodejs and i am trying to make an update request in dynamoDB that should execute only if a conditional expression validate to true. For that, I check if in the request body object (parsedBody) there is a key called crypto.

So, this is part of my code (docClient is an instance of AWS.dynamoDB...):

enter image description here

However, if I execute this code, I got this error here:

enter image description here

So, please, can someone explain to me what am I getting wrong here?

Cheers, Marcelo

1

There are 1 answers

4
Kira On

EDIT:

From AWS Docs,

"You specified a condition that evaluated to false. For example, you might have tried to perform a conditional update on an item, but the actual value of the attribute did not match the expected value in the condition."

So the behavior is correct.

You can try to use https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html to update an Item just in case your condition is satisfied.


The conditional expression is executed on Dynamo side and not on your server.

I think the object persedBody does not exists on DB, so you could try to pass just the 'crypto' as argument of the attribute_exists function.

Something like: ConditionalExpression: 'attribute_exists(crypto)'