Advertisement
shubhamgoyal

Untitled

Mar 19th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const updateTTLForItem = (partitionKey, sortKey) => {
  2.   const expirationDate = new Date()
  3.   expirationDate.setHours(expirationDate.getHours() + 7 * 24)
  4.   const ttlEpochTime = Math.round(expirationDate.getTime() / 1000)
  5.   const params = {
  6.     ExpressionAttributeNames: {
  7.       "#TTL": "ttl",
  8.     },
  9.     ExpressionAttributeValues: {
  10.       ":ttl": {
  11.         N: ttlEpochTime.toString(),
  12.       },
  13.     },
  14.     Key: {
  15.       "Device_Browser": {
  16.         S: partitionKey,
  17.       },
  18.       "URL": {
  19.         S: sortKey,
  20.       },
  21.     },
  22.     ReturnValues: "ALL_NEW",
  23.     TableName: "dex-v6-items-new",
  24.     UpdateExpression: "SET #TTL = :ttl",
  25.   }
  26.   dynamodb.updateItem(
  27.     params,
  28.     (err, data) => {
  29.       if (err) {
  30.         console.log(err, err.stack)
  31.       } else {
  32.         console.log(data)
  33.       }
  34.     }
  35.   )
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement