set in dynamo db not properly incrementing nodejs lamnda function

Solutions on MaxInterview for set in dynamo db not properly incrementing nodejs lamnda function by the best coders in the world

showing results for - "set in dynamo db not properly incrementing nodejs lamnda function"
Benjamin
13 Sep 2019
1var AWS = require('aws-sdk');
2var documentClient = new AWS.DynamoDB.DocumentClient({'region': 'eu-central-1'});
3
4exports.handler = function(item, context, callback) {
5
6    var params = {
7        TableName: "my-table",
8        Key:{
9            "id": item.id
10        },
11        UpdateExpression: "ADD iteration :iteration SET itemdata = :itemdata",
12        ExpressionAttributeValues:{
13            ':iteration': 1,
14            ':itemdata' : item.data
15        },
16        ReturnValues:"NONE"
17};
18
19documentClient.update(params, function(err, data) {
20    if (err) {
21      console.log("Error", err);
22      const errResponse = {
23        statusCode: 500,
24        headers: {
25          "Access-Control-Allow-Origin": "*"
26        },
27        body: JSON.stringify({ Error: 500, device : "DynamoDB", detail : err })
28      };
29      callback(null, errResponse);
30    } else {
31      console.log("Success", params.Items);
32      const response = {
33        statusCode: 200,
34        headers: {
35          "Access-Control-Allow-Origin": "*"
36        },
37        body: JSON.stringify("upsert complete.")
38      };
39      callback(null, response);
40    }
41  });
42};