admin管理员组文章数量:1313614
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).
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.
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.
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.
Sample code:
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
});
Among the things I've tried: create a new AWS.Lambda()
for each invocation.
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).
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.
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.
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.
Sample code:
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
});
Among the things I've tried: create a new AWS.Lambda()
for each invocation.
2 Answers
Reset to default 4According 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).
You need to set the timeout on the lambda that is calling lambda.invoke, not on the lambda.invoke itself (as you are doing with options
).
So, if you have LambdaA
that invokes LambdaB
, the timeout on LambdaA
has to be the same as (or higher than) the timeout for LambdaB
, otherwise LambdaA
will potentially timeout before LambdaB pletes.
I presume that the code you are providing is running in a lambda. You need to set the timeout on that lambda.
The options
you are using to create AWS.Lambda can be discarded in the code you've provided here.
本文标签: javascriptAWS Lambda invoke function (js sdk) timeout resets to defaultStack Overflow
版权声明:本文标题:javascript - AWS Lambda invoke function (js sdk): timeout resets to default - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741929273a2405477.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论