Querying DynamoDB with Lambda does nothing

前端 未结 6 825
北恋
北恋 2021-02-07 09:01

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         


        
6条回答
  •  清酒与你
    2021-02-07 09:35

    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.

提交回复
热议问题