I have the following code for a Lambda function:
console.log(\'Loading function\');
var aws = require(\'aws-sdk\');
var ddb = new aws.DynamoDB();
function getUs
I had some similar issues and did not find many helpful resources. Here's what I ended up doing. Probably someone smarter can tell us if this is bestest.
function getHighScores(callback) {
var params = {
TableName : 'sessions',
ScanFilter: {"score":{"AttributeValueList":[{"N":"0"}], "ComparisonOperator":"GT"}},
};
var dynamo = new AWS.DynamoDB();
dynamo.scan(params, function(err, data) {
if (err) {
console.log (err)
callback(err);
} else {
callback(data.Items);
console.log(data.Items);
}
});
}
getHighScores(function (data) {
console.log(data);
context.succeed(data);
});
In summary, having the passback of callback through the main function to the smaller function, allows the application to continue until completing the Dynamo. Keep the context.succeed in the secondary function or continue other function there.