'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:
How can I have a function that lasts 15 minutes, but a Gateway that time outs after 30 seconds?
Solution 1:[1]
API Gateway now has support to WebSocket APIs. Just:
- Create a websocket,
- call a lambda function through this socket, passing the connectionid to it. that lambda will then put a message in a SQS queue passing the connectionid
- the final lambda called by sqs to process the queue in an async event will perform its duties (up to 15min of processing), and then will use the connectionid to communicate to the client (browser) the results of the processing (just like a regular lambda would do through api gateway).
you can event check if the connection is still alive to interrupt processing (or send a message of progress back to the client).
Solution 2:[2]
Currently there is no way to increase the API timeout seconds. Another options is to create an ALB and forward request to Lambda.
Solution 3:[3]
Just a note here, even if your lambda "times out" it will still finish whatever code is running. So your frontend user will get a timeout error but it will continue running.
Solution 4:[4]
Another option is to create an EventBridge timer with a quick API call and have the Lambda executed from the timer.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Emerson Lopes |
| Solution 2 | Xing-Wei Lin |
| Solution 3 | Leander |
| Solution 4 | Alexander Shcheblikin |

