I'm trying to update an item in Amazon DynamoDB. I want to execute an operation that consists of one sum and one subtraction, but I'm not able to accomplish my goal.
Here is the function, ddb is an instance of the class AWS.DynamoDB.DocumentClient:
function updateLecture(event){
const params = {
TableName: 'lecture',
Key: {
'lecture_id': Number.parseInt(event.lecture_id)
},
UpdateExpression: 'SET #free = :total - (#total + #free)',
ExpressionAttributeValues: {
':total': event.total
},
ExpressionAttributeNames: {
"#total" : "total",
"#free" : "free"
},
ReturnValues : 'UPDATED_NEW'
}
return ddb.update(params).promise();
}
When I try to run the function, I get the following error:
"errorType": "ValidationException",
"errorMessage": "Invalid UpdateExpression: Syntax error; token: \"+\", near: \"#total + #free\""
I've tried to work with parenthesis, but I always receive the same error.
I'm afraid I can't use more than one operation, but I couldn't find any trace of that in the docs. Anyway, is there a way to use multiple operations?