AWS Lambda调用函数并不总是返回

编程入门 行业动态 更新时间:2024-10-24 22:26:39
本文介绍了AWS Lambda调用函数并不总是返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用节点4.3作为运行时.我正在使用节点 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调用函数并不总是返回

本文发布于:2023-11-27 06:37:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636987.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   AWS   Lambda

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!