Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Alexa AWS错误:任务在3.00秒后超时_Node.js_Request_Aws Lambda_Cheerio_Alexa Skill - Fatal编程技术网

Node.js Alexa AWS错误:任务在3.00秒后超时

Node.js Alexa AWS错误:任务在3.00秒后超时,node.js,request,aws-lambda,cheerio,alexa-skill,Node.js,Request,Aws Lambda,Cheerio,Alexa Skill,我正在尝试编写一个Alexa技巧,它使用request.js&cheerio.js对数据进行一些web抓取 当我在本地运行它时,它工作正常,正如预期的那样,但在AWS lambda实例上,我不断收到超时错误,因为完成运行需要3秒以上的时间。错误日志如下所示: START RequestId: 57f84024-6ef5-11e8-b49f-37c904d87c93 Version: $LATEST 2018-06-13T10:34:26.850Z 57f84024-6ef5-11e

我正在尝试编写一个Alexa技巧,它使用request.js&cheerio.js对数据进行一些web抓取

当我在本地运行它时,它工作正常,正如预期的那样,但在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
导致问题的代码片段是:

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(),但是我得到了未定义的错误“cannotdo.on”

以前有人吃过类似的东西吗

问题已解决:


在Lambda设置屏幕中将超时设置设置为更高的数字。有点黑,你需要确保你有良好的错误处理。但它现在起作用了啊,只是根据答案找到的。我想我会添加图像


IMO的可能副本,而不是黑客-这是正确的解决方案。对于感兴趣的用户,可在此处找到Lambda配置选项的文档: