AWS Lambda and Serverless Timeout

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值