AWS Lambda and Serverless Timeout
Recently, we found a bug in my codes which the lambda function only delete parts of my resources in a for loop.
Finally we found out that because we are using for loop to delete 20 third party resources, it take about 1 second to delete 1 resources. After 6 seconds, it is timeout and the event get re-try and send to our lambda again from SNS.
So in our serverless configuration, it is default to 6 seconds, we can change that as follow:
# serverless.yml
service: myService
provider:
name: aws
runtime: nodejs6.10
memorySize: 512 # optional, in MB, default is 1024
timeout: 10 # optional, in seconds, default is 6
versionFunctions: false # optional, default is true
functions:
hello:
handler: handler.hello # required, handler set in AWS Lambda
name: ${self:provider.stage}-lambdaName # optional, Deployed Lambda name
description: Description of what the lambda function does # optional, Description to publish to AWS
runtime: python2.7 # optional overwrite, default is provider runtime
memorySize: 512 # optional, in MB, default is 1024
timeout: 10 # optional, in seconds, default is 6
reservedConcurrency: 5 # optional, reserved concurrency limit for this function. By default, AWS uses account concurrency limit
In general, we should not relay on the longer timeout, we should design this async at the beginning.
References:
https://github.com/serverless/serverless/blob/91fc7c97e64170cdc9cbc63fb0f08a337991c107/lib/plugins/aws/deploy/compile/functions/index.js#L56
https://serverless.com/framework/docs/providers/aws/guide/functions/
Recently, we found a bug in my codes which the lambda function only delete parts of my resources in a for loop.
Finally we found out that because we are using for loop to delete 20 third party resources, it take about 1 second to delete 1 resources. After 6 seconds, it is timeout and the event get re-try and send to our lambda again from SNS.
So in our serverless configuration, it is default to 6 seconds, we can change that as follow:
# serverless.yml
service: myService
provider:
name: aws
runtime: nodejs6.10
memorySize: 512 # optional, in MB, default is 1024
timeout: 10 # optional, in seconds, default is 6
versionFunctions: false # optional, default is true
functions:
hello:
handler: handler.hello # required, handler set in AWS Lambda
name: ${self:provider.stage}-lambdaName # optional, Deployed Lambda name
description: Description of what the lambda function does # optional, Description to publish to AWS
runtime: python2.7 # optional overwrite, default is provider runtime
memorySize: 512 # optional, in MB, default is 1024
timeout: 10 # optional, in seconds, default is 6
reservedConcurrency: 5 # optional, reserved concurrency limit for this function. By default, AWS uses account concurrency limit
In general, we should not relay on the longer timeout, we should design this async at the beginning.
References:
https://github.com/serverless/serverless/blob/91fc7c97e64170cdc9cbc63fb0f08a337991c107/lib/plugins/aws/deploy/compile/functions/index.js#L56
https://serverless.com/framework/docs/providers/aws/guide/functions/
解决AWS Lambda超时问题

本文探讨了AWS Lambda函数在处理资源删除时遇到的超时问题,并提供了通过修改serverless.yml配置文件来调整超时时间的解决方案。同时,强调了在设计Lambda函数时考虑异步处理的重要性。
4065

被折叠的 条评论
为什么被折叠?



