Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

set in Dynamo DB not properly incrementing nodejs lamnda function

var AWS = require('aws-sdk');
var documentClient = new AWS.DynamoDB.DocumentClient({'region': 'eu-central-1'});

exports.handler = function(item, context, callback) {

    var params = {
        TableName: "my-table",
        Key:{
            "id": item.id
        },
        UpdateExpression: "ADD iteration :iteration SET itemdata = :itemdata",
        ExpressionAttributeValues:{
            ':iteration': 1,
            ':itemdata' : item.data
        },
        ReturnValues:"NONE"
};

documentClient.update(params, function(err, data) {
    if (err) {
      console.log("Error", err);
      const errResponse = {
        statusCode: 500,
        headers: {
          "Access-Control-Allow-Origin": "*"
        },
        body: JSON.stringify({ Error: 500, device : "DynamoDB", detail : err })
      };
      callback(null, errResponse);
    } else {
      console.log("Success", params.Items);
      const response = {
        statusCode: 200,
        headers: {
          "Access-Control-Allow-Origin": "*"
        },
        body: JSON.stringify("upsert complete.")
      };
      callback(null, response);
    }
  });
};
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #set #Dynamo #DB #properly #incrementing #nodejs #lamnda #function
ADD COMMENT
Topic
Name
8+9 =