【问题标题】:Alexa AWS Error: task timed out after 3.00 secondsAlexa AWS 错误:任务在 3.00 秒后超时
【发布时间】:2018-11-22 23:41:39
【问题描述】:

我正在尝试编写一个 Alexa 技能,该技能使用 request.js 和 Cheerio.js 来执行一些网络抓取数据。

当我在本地运行它时,它可以正常工作,正如预期的那样,但在 AWS lambda 实例上,我不断收到超时错误,因为它需要超过 3 秒才能完成运行。错误日志是这样的:

    START RequestId: 57f84024-6ef5-11e8-b49f-37c904d87c93 Version: $LATEST
2018-06-13T10:34:26.850Z    57f84024-6ef5-11e8-b49f-37c904d87c93    NEW SESSION
2018-06-13T10:34:26.851Z    57f84024-6ef5-11e8-b49f-37c904d87c93    INTENT REQUEST
2018-06-13T10:34:26.851Z    57f84024-6ef5-11e8-b49f-37c904d87c93    Sid started
2018-06-13T10:34:26.851Z    57f84024-6ef5-11e8-b49f-37c904d87c93    INTENT FOR SID HAS STARTED
2018-06-13T10:34:26.851Z    57f84024-6ef5-11e8-b49f-37c904d87c93    https://en.wikipedia.org/wiki/Chloroform
2018-06-13T10:34:26.950Z    57f84024-6ef5-11e8-b49f-37c904d87c93    SESSION END REQUEST
2018-06-13T10:34:27.731Z    57f84024-6ef5-11e8-b49f-37c904d87c93    REQUEST MADE
2018-06-13T10:34:27.731Z    57f84024-6ef5-11e8-b49f-37c904d87c93    trying to use cheerio to load page now
END RequestId: 57f84024-6ef5-11e8-b49f-37c904d87c93
REPORT RequestId: 57f84024-6ef5-11e8-b49f-37c904d87c93  Duration: 3003.16 ms    Billed Duration: 3000 ms    Memory Size: 128 MB Max Memory Used: 48 MB  
2018-06-13T10:34:29.499Z 57f84024-6ef5-11e8-b49f-37c904d87c93 Task timed out after 3.00 seconds

导致问题的代码sn-p是:

var URL = 'https://en.wikipedia.org/wiki/' + searchTerm;
                            console.log(URL)
                            request(URL, function(error, response, html){
                                console.log('REQUEST MADE');
                                try {
                                    console.log( 'trying to use cheerio to load page now')
                                    if (html){
                                    var $ = cheerio.load(html);
                                        console.log('PAGE LOADED');
                                        var infobox = $('table.infobox').children('tbody');
                                        infobox.children().each(function(i, element){
                                            var row = $(this);
                                            if(row.children().first().children().first().text() == 'GHS hazard statements') {
                                                var hCodes = row.first().first().text().toString();
                                                var pPhrases = row.first().next().text().toString();
                                                context.succeed(
                                                    generateResponse(
                                                        buildSpeechletResponse(`I found the following ` + hCodes + ` ` + pPhrases, true),
                                                        {}
                                                        ))
                                            }
                                        })

                                } else {
                                    console.log('There was no HTML loaded. Please try again')
                                } 
                                } catch(error){
                                    console.log(error)
                                    console.log('THERE WAS AN ERROR PLEASE TRY AGAIN')
                                }

                            })

我也尝试过使用 response.on(),但我收到未定义的错误“Cannot do .on”。

以前有人遇到过这种情况吗?

【问题讨论】:

标签: node.js request aws-lambda cheerio alexa-skill


【解决方案1】:

啊,根据回答才找到的。以为我会添加图片。

【讨论】:

    【解决方案2】:

    问题已解决:

    在 Lambda 设置屏幕中将超时设置设置为更高的数字。有点老套,你需要确保你有良好的错误处理。但是现在可以了??

    希望这可以帮助其他人。 ?

    【讨论】:

    【解决方案3】:

    AWS Lambda "errorMessage": Task timed out after 3.00 seconds

    我有同样的错误 - 增加超时解决了它:

    在 AWS 管理控制台中:

    lambda function -> configuration -> General configuration -> Edit Timeout
    

    【讨论】:

      猜你喜欢
      • 2018-08-08
      • 2020-11-06
      • 2017-12-09
      • 2018-05-15
      • 1970-01-01
      • 2020-11-18
      • 2019-01-28
      • 2021-05-30
      • 2022-07-20
      相关资源
      最近更新 更多