Search code examples
amazon-web-servicesaws-lambda

How can I set the AWS API Gateway timeout higher than 30 seconds?


I read here that I can set my Lambda function timeout for 15 minutes (https://aws.amazon.com/about-aws/whats-new/2018/10/aws-lambda-supports-functions-that-can-run-up-to-15-minutes/)

However, when I try to set API Gateway inside the Integration Request settings, it does not allow me to set it higher than 29seconds:

Timeout max is 29 seconds

How can I have a function that lasts 15 minutes, but a Gateway that time outs after 30 seconds?


Solution

  • Unfortunately there isn't a way to increase the API Gateway timeout to longer than 29 seconds. This is a limitation of the gateway. The reason you can set the lambda function longer is because this can be plugged into other AWS resources that allow a higher threshold for timeout processing.

    Here's some options you could explore to get around this and/or work with the limitation:

    1. Split your function out into smaller functions and chain those together to see if you get a performance increase. Before doing so you could use AWS X-Ray to debug the function and see what part is taking the most time to target what needs to be split out.

    2. Increase the memory used by the function. Higher memory allocation could result in faster execution. I have used this option before and was able to work around timeout limits.

    3. Instead of using API Gateway you could just use AWS SDK to call 'invoke()' which will invoke your lambda function. This will bypass the timeout threshold.

    Hopefully one or a mix of those will help out :)