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/