shashank patel
shashank patel

Reputation: 167

lambda not updating DynamoDB data on first run but updates on second run

I have a lambda function which is updating data in DynamoDB table(Based on specific user properties I want to change some values for that user.). When It gets executed first time then it doesn't work, but on second execution it updates the data. It works alternatively. one time it updates and one time it doesn't. What could be the reason for this.

Based on specific user properties I want to change some values for that user.

Upvotes: 1

Views: 779

Answers (1)

Tristan Müller
Tristan Müller

Reputation: 412

This sounds like a syntax error while using or not using await and .promise()

Also out of experience there occur problems like you described it when you call it like this:

await nameOfDb.update(params, function (err, data) {   
      if (err) console.log(err, err.stack);   
      else     console.log(data); 
}).promise();

which is the recommended way to call .update() in the doc

so I prefer using

Try {
    await nameOfDb.update(params).promise();
} 
catch (e) {
    console.log(e);
}

which always works as I want it to work when using .update()

Upvotes: 1

Related Questions