Skip to content

Instantly share code, notes, and snippets.

@sebsto sebsto/async4.js
Created Jun 25, 2019

Embed
What would you like to do?
Async - AWS SDK for Javascript
function updatePlayCount(your_object) {
return new Promise((resolve, reject) => {
const LAST_PLAYED_TIME = Math.round(new Date() / 1000);
var params = {
TableName: "your_table",
Key: {
"cognitoid": your_object.userId,
"creationtime": your_object.creationtime
},
UpdateExpression: "SET lastPlayed = :time ADD playedCount :val",
ExpressionAttributeValues:{
":val": 1,
":time": LAST_PLAYED_TIME
}
};
var documentClient = new AWS.DynamoDB.DocumentClient();
documentClient.update(params, (err, data) => {
if (err) {
console.log("Error when updating DynamoDB");
console.log(err); // an error occurred
console.log(JSON.stringify(params,null,2));
reject(err);
} else {
// console.log(data); // successful response
resolve(data);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.