I'm trying to perform a update call to a DynamoDB.DocumentClient
instance using AWS SDK
with the payload on the code snippet below:
const AWS = require('aws-sdk')
const DynamoDB = new AWS.DynamoDB.DocumentClient()
...
const TableName = 'MyTable'
const Key = { PK: 'MyPK', SK: 'MySK' }
const operation = 'DELETE'
const myId = 'abcde'
const currentRecord = await DynamoDB.get({TableName, Key)
DynamoDB.update({
TableName,
Key,
UpdateExpression: `
${operation} myIds :valuesToModify,
version :incrementVersionBy
`,
ConditionExpression: `version = :version`,
ExpressionAttributeValues: {
":version": currentRecord.version,
":incrementVersionBy": 1,
":valuesToModify": DynamoDB.createSet([myId])
}
})...
I get this error as result:
ERROR Invoke Error
{
"errorType":"Error",
"errorMessage":"ValidationException: Invalid UpdateExpression: Incorrect operand type for operator or function;
operator: DELETE, operand type: NUMBER, typeSet: ALLOWED_FOR_DELETE_OPERAND",
"stack":[...]
}
Interestingly, if operation
is changed to ADD
it works well.
Any clues that could be helpful to understand why ADD
works and not DELETE
and/or how to fix and/or yet alternative approaches compatible with this update operation are highly appreciated!