AWS Lambda调用函数(js sdk):超时重置为默认值 [英] AWS Lambda invoke function (js sdk): timeout resets to default

查看:91
本文介绍了AWS Lambda调用函数(js sdk):超时重置为默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个流星(节点4.4.7)应用程序,该应用程序在AWS Lambda上执行长时间的操作.我从代码中调用了lambda函数,并等待响应,然后再进行下一次调用.我按照以前的问题(两者均设置)中的说明将超时设置为300000ms在Lambda和我的代码中的AWS.Lambda对象中.

I am running a Meteor (Node 4.4.7) application that performs long operations on AWS Lambda. I invoke the lambda function from my code and wait for the response before proceeding to the next invocation. I set the timeout to 300000ms as described in a former question (both on Lambda and in the AWS.Lambda object in my code).

我的问题是,有时 AWS.Lambda 超时值会重置为默认值120000ms.由于我的Lambda函数需要花费更多时间执行(但仍少于最大300秒),因此我没有收到响应.此外,我看到我的函数根据默认的 maxRetries 值又被调用了3次,即使我将其设置为1.

My problem is that sometimes the AWS.Lambda timeout value is reset to the default value of 120000ms. As my Lambda function takes more time to execute (but still less than the max 300s), I don't receive the response. Furthermore I see that my function is invoked 3 more times as per the default maxRetries value, even thought I set it to 1.

我不知道复制它的步骤.似乎是随机的.通常会在运行我的应用几天后发生.如果我检查 AWS.Lambda 对象的属性,尽管它的行为就像具有默认的120000ms,但它仍然具有300000ms超时值.一旦发生这种情况,所有后续调用请求都会遇到相同的问题,我必须重新启动该应用程序才能使其再次运行.

I don't know the steps to reproduce it. It seems random. It usually happens after a couple of days running my app. If I check the properties of my AWS.Lambda object, it still has the 300000ms timeout value although it behaves like it has the default 120000ms value. Once this happens, all subsequent invocations requests have the same problem and I have to restart the app to make it work again.

请注意,在Lambda日志上,我看到这些函数正在正确执行.持续时间<120s返回我的代码.持续时间> 120秒.

Note that on the Lambda logs, I see that the functions is being executed properly. Duration < 120s returns in my code. Duration > 120s are retried.

示例代码:

var options = {
  maxRetries: 1,
  httpOptions: {
    timeout: 300000
  }
};

var lambda = new AWS.Lambda(options);

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
});

在我尝试过的事情中:为每次调用创建一个新的AWS.Lambda().

Among the things I've tried: create a new AWS.Lambda() for each invocation.

推荐答案

根据SDK 文档,AWS中的 httpOptions.timeout 键.Lambda不是函数超时-它是套接字超时.这是有道理的,因为Lambda函数的默认超时为3秒,而不是2分钟.

According to the SDK documentation, the httpOptions.timeout key in AWS.Lambda isn't the function timeout - it's the socket timeout. That makes some sense, because the default timeout for a Lambda function is 3 seconds, not 2 minutes.

您可以使用

You can change the function timeout in your code using the updateConfiguration method. Or, if you're using the Serverless Framework to deploy your Lambda functions, you can set the timeout in the serverless.yml. And of course, you can always set the timeout in the AWS console (I've had issues with configurations set in the console being wiped out when I deploy with Serverless/CloudFormation, but I don't know how you're deploying - it shouldn't be an issue if you're just reading code for S3 or uploading a ZIP).

这篇关于AWS Lambda调用函数(js sdk):超时重置为默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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