I am running an AWS Lambda service written in Node.js that interacts with a DynamoDB database. One of my methods performs an update (AWS.DynamoDB.DocumentClient().update) on
ConditionExpression is the way to go, but you can also use the attribute_exists
function :
ConditionExpression: 'attribute_exists(userId)'
It will only update the line with the correct key and throw a ConditionalCheckFailedException
if requested key doesn't exist.
The goal is more obvious and you can skip the extra userId binding.
ref : https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html