Skip to content

Instantly share code, notes, and snippets.

@sebsto
Created June 25, 2019 09:07
Show Gist options
  • Save sebsto/96595219569f2335891d00415e2d1569 to your computer and use it in GitHub Desktop.
Save sebsto/96595219569f2335891d00415e2d1569 to your computer and use it in GitHub Desktop.
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