Alexa Lambda DynamoDB什么都不返回

问题描述 投票:0回答:1

我无法弄清楚为什么我在Alexa Skill中看不到DynamoDB的任何响应。

我使用不同来源的DynamoDB创建了承诺的几种变体来弄清楚。但似乎没有任何效果。日志中甚至没有DynamoDB的一个错误。这让我发疯了。

我试过扫描,获取和放置操作。

这里我的扫描代码在AWS lambda中尝试:

....

'StartIntent': function () {
    speechOutput = '';

    var AWS = require('aws-sdk');
    AWS.config.update({region: 'eu-west-1'});

    var docClient = new AWS.DynamoDB.DocumentClient();

    var params = {
        TableName: "my_db_2",
        FilterExpression: "data_type = card"
    };

    console.log("Scanning table.");

    docClient.scan(params, onScan).promise().then(function(result)  {
        console.log("GetItem succeeded:", JSON.stringify(result, null, 2));
        console.log("succeeded");
        }).catch(error => {
    console.log("ERROR catched");
    });
    console.log("scan done");

},

.....


function onScan(err, data) {
    console.log("starting to scan");
    if (err) {
        console.error("Unable to scan the table. Error JSON:", 
        JSON.stringify(err, null, 2));
    } 
    else {
        console.log("Scan succeeded.");
        data.Items.forEach(function(movie) {
           console.log(movie.data_type);
        });
    }
}

Cloudwatch仅显示:

2018-09-13T11:43:11.500Z扫描台。

2018-09-13T11:43:11.522Z扫描完成

2018-09-13T11:43:11.659Z扫描第2次完成

amazon-web-services aws-lambda amazon-dynamodb alexa-skill
1个回答
0
投票

scan不同步。您正在使用承诺来封装异步行为。基本上console.log("Scanning table.")console.log("scan done")会被立即调用,因为它们是同一个同步块的一部分。然后当scan操作完成时,将调用console.log("succeeded")。由于您似乎没有等待扫描完成,因此我假设您的lambda在从DynamoDB返回数据之前已经退出。

© www.soinside.com 2019 - 2024. All rights reserved.