I am trying to update an existing DynamoDB table record that contains an ID of 0c876d54-195a-46d1-954c-80477e78e70e and set the status column from true to false. I'm using a Lambda function with Node.js to perform the update. The function returns null and there seems to be little documentation to performs what should be such a simple task. Here is what I have tried:
const AWS = require('aws-sdk');
const ddb = new AWS.DynamoDB.DocumentClient({ region: 'us-east-1' });
exports.handler = async(event, context, callback) => {
await updateTable().then(() => {
callback(null, {
statusCode: 201,
body: '',
headers: {
'Access-Control-Allow-Origin': '*'
}
});
}).catch((err) => {
console.error(err)
})
};
function updateTable() {
const params = {
TableName: "MyTable",
Key: {
"ID": "0c876d54-195a-46d1-954c-80477e78e70e"
},
UpdateExpression: "SET status = :status",
ExpressionAttributeValues: {
":status": "FALSE"
}
}
return ddb.update(params).promise();
}