JavaEar 专注于收集分享传播有价值的技术资料

AWS Lambda Task timed out after 6.00 seconds

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 disabled. AWS Lambda function has 128MB memory allocated.

I have used Jmeter for performance testing.I have sent 1000 requests concurrently and some response giving me perfect output while other giving internal server error(502 Bad Gateway). i have also analyzed cloudwatch for logs and only get Task Timeout error. can anyone suggest me why i am getting this error and how to solve it?


  1. Since you mentioned that your DynamoDB table isnprovisioned with only 5 WCU this means that only 5 weites are allowed per second.

    DynamoDB does offer burst capacity allowing ypu to use 300 seconds worth of accumulated capacity (which at 5 WCU it is equivalent to 1500 writes) 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 if it is being throttled heavily.

    Your Lambda function is very lively timing put at 5 seconds because the function's code 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.

  2. 参考答案2
  3. 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:

        timeout: 10 # optional, in seconds, default is 6