本文介绍了Lambda函数在完成后超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个lambda函数,该函数可以完成而没有错误(到达console.log()行),但是仍然超时.我已经尝试使用lambda-local进行调试,但是找不到挂起的位置.我在处理程序函数中读取了多个应该包含context.callbackWaitsForEmptyEventLoop = false的位置,但这没有任何区别.我是否还有其他遗漏或未调用的内容,导致该函数无法超时?在打印consol.log()函数,END RequestID和REPORT RequestID之后,此错误被打印2018-11-05T23:42:24.357Z 705cea03-e154-11e8-8089-87f7086f1090 Task timed out after 3.00 seconds

I have a lambda function that is completing without errors (I get to the console.log() line), but still times out. I have tried debugging with lambda-local, but cannot find where the hold up is. I read multiple places that I should include context.callbackWaitsForEmptyEventLoop = false in my handler function, but that makes no difference error. Is there something else I'm missing or not calling that is preventing this function from not timing out? After the consol.log() function gets printed, END RequestID, and REPORT RequestID, this error gets printed 2018-11-05T23:42:24.357Z 705cea03-e154-11e8-8089-87f7086f1090 Task timed out after 3.00 seconds

这是我的处理程序的功能:

Here is my handler's function:

exports.handler = function(event, context, callback) {
    context.callbackWaitsForEmptyEventLoop = false
    let alexa = Alexa.handler(event, context);
    alexa.APP_ID = APP_ID;
    // To enable string internationalization (i18n) features, set a 
resources object.
    alexa.resources = languageStrings;
    alexa.registerHandlers(handlers);
    alexa.execute();
    console.log("You made it.")
};

推荐答案

您缺少回调.

exports.handler = function(event, context, callback) {
    context.callbackWaitsForEmptyEventLoop = false
    let alexa = Alexa.handler(event, context);
    alexa.APP_ID = APP_ID;
    // To enable string internationalization (i18n) features, set a 
resources object.
    alexa.resources = languageStrings;
    alexa.registerHandlers(handlers);
    alexa.execute();
    console.log("You made it.")
    callback(null,"Complete");
};

因为您已禁用callbackWaitsForEmptyEventLoop.它将等到您启动callback函数调用.

Since you have disabled callbackWaitsForEmptyEventLoop. It is going to wait until you initiate the callback function call.

希望它会有所帮助.

这篇关于Lambda函数在完成后超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:33