Reputation: 43
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\"}]"
}
Upvotes: 0
Views: 453
Reputation: 2452
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
Upvotes: 1