AWS Lambda Task timed out after 6.00 seconds

后端 未结 2 1985
有刺的猬
有刺的猬 2021-02-12 14:09

I am using serverless framework. My Lambda function connects to DynamoDB table for updating item in table. Read & Write capacity units of table are 5 & auto_scaling is d

相关标签:
2条回答
  • 2021-02-12 14:31

    The default timeout for AWS Lambda functions when using the Serverless framework is 6 seconds. Simply change that to a higher value as noted in the documentation:

    functions:
      hello:
        ...
        timeout: 10 # optional, in seconds, default is 6
    
    0 讨论(0)
  • 2021-02-12 14:36

    Since you mentioned that your DynamoDB table is provisioned with only 5 WCU this means that only 5 writes are allowed per second.

    DynamoDB does offer burst capacity allowing you to use 300 seconds worth of accumulated capacity (which at 5 WCU it is equivalent to 1500 total write requests) but as soon as those are exhausted it will start to throttle.

    The DynamoDB client has automatic retries built in, with exponential backoff and it is smart enough to recognize throttling so it will slow down the retries to the point that a single write can easily take several seconds to complete successfully if it is being repeatedly throttled.

    Your Lambda function is very likely timing out at 6 seconds because the function is waiting on retries to Dynamo.

    So, when doing load testing make sure that your dependencies are all scaled appropriately. At 1000 requests per second you should make sure to scale the Read/Write capacity allocation for your DynamoDB table(s) and/or Index(s) accordingly.

    0 讨论(0)
提交回复
热议问题