0

I have written simple Lambda function to scan data from dynamodb, but data is getting retrieved with error message tag and lambda function shows message as execution failed

    var AWS = require('aws-sdk');
    var DOC = require("dynamodb-doc");
    var dynamo = new DOC.DynamoDB();
    exports.handler = function (event, context, callback) {

     var params = {
        TableName: "Movies",
       // ProjectionExpression: "#yr, Movie",
        FilterExpression: "#yr = :thisyear",
        ExpressionAttributeNames: {
        "#yr": "year",
    },
    ExpressionAttributeValues: {
         ":thisyear" : 2009
    }       
};

  dynamo.scan(params, function(err, data){
          if (err){
        callback("error occoured");
          }
          else{
        callback(JSON.stringify(data.Items));
          }          
  });
  };

Result

{
  "errorMessage": "[{\"year\":2009,\"Movie\":\"Jab tak hai jaan\"}]"
}

1 Answer 1

1

nodejs callback are typically error-first callbacks. It means that the first parameter is the error message and the second parameter is the result. So when returning the result you need to pass null as the first argument. eg: callback(null, JSON.stringify(data.Items));

Please refer this article

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.