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

API Gateway now has support to WebSocket APIs. Just:

  1. Create a websocket,
  2. 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
  3. 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).


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 :)


Currently there is no way to increase the API timeout seconds. Another options is to create an ALB and forward request to Lambda.


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.

Tags:

Aws Lambda