AWS Lambda调用函数并不总是返回 [英] AWS Lambda invoke function doesn't always return

查看:100
本文介绍了AWS Lambda调用函数并不总是返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 aws-sdk .

I am running an AWS Lambda function for image/video processing with Node 4.3 as a runtime. I am invoking my function from my webapp code with the node aws-sdk.

问题在于,尽管该函数执行时间较长(例如250秒),但从未收到调用回调,尽管我可以在aws cloudwatch日志中清楚地看到该函数已正确执行.最重要的是,该函数至少再次重新运行两次(这可能与调用中的maxRetries参数有关:因为它没有得到返回的响应,因此会重试).

The issue is that when the function takes a long time to execute (e.g. 250 seconds), the invocation callback is never received, although I can clearly see in the aws cloudwatch logs that the function executed properly. On top of that the function is re-run again at least twice (this is probably related to the maxRetries parameter from the invocation: since it doesn't get a response back it retries).

让我感到困惑的是,它可以用于更快的功能,而我的lambda函数永不超时.有人遇到这样的问题吗?它可以与新的4.3运行时相关吗?请注意,由于不再需要context.succeed()context.fail(),因此我将其省略了,但是我尝试使用它并且它不会改变任何事情.

What confuses me is that it works for quicker functions and my lambda function never times out. Anyone having such an issue ? Can it be related to the new 4.3 runtime? Note that I omit the context.succeed()or context.fail() as it is not required anymore, but I tried with it and it doesn't change a thing.

Lambda代码

...
var handler = function (event, context, callback) {
    // video/image processing code
    // 
    // callback function
    ..., function(err, result) {
        if (err) {
            console.log("Error", err, err.stack);
            callback(err);
        } else {
            console.log("Done");
            callback(null, result);
        }
    }
};

Lambda调用

var lambda = new AWS.Lambda;

var myEventObject = {...};
var payload = JSON.stringify('myEventObject');

var params = {
    FunctionName: 'myLambdaFunction'
    InvocationType: 'RequestResponse',
    LogType: 'None',
    Payload: payload
};

lambda.invoke(params, function(err, data) {
    if (err) console.log(err, err.stack); // an error occurred
    else     console.log(data);           // successful response
});

Lambda CloudWatch Log

REPORT RequestId: xxx   Duration: 206757.82 ms  Billed Duration: 206800 ms Memory Size: 1536 MB Max Memory Used: 354 MB 

如注释中所述,

推荐答案

aws sdk具有其自己的超时配置设置,默认情况下设置为120秒(这是与lambda一).

as stated within the comments, the aws sdk has its own timeout config setting, that is by default set to 120 seconds (this is a different timeout setting than the lambda one).

在当前情况下,由于lambda在此超时时间内运行的时间更长,因此sdk会假设发生故障并触发重试.

in the current case, as the lambda runs for more this timeout, the sdk is assuming a failure and firing retries.

将此配置设置为300秒应该可以解决该问题.正如Daniel T在评论中所示,可以通过以下方式临时更改此设置:var lambda = new AWS.Lambda({httpOptions {timeout:300000}});

setting this config to 300 seconds should solve the problem. As Daniel T showed in the comment, temporary changing this can be achieved this way: var lambda = new AWS.Lambda({httpOptions{timeout: 300000}});

这篇关于AWS Lambda调用函数并不总是返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆