6

AWS API Gateway timeout after around 30 seconds. I connected the API gateway to a lambda function that runs far longer than 30 seconds.

So the API response times out after around ~30 seconds and give back something like a timeout response.

How do I solve this problem and get my response back from Lambda?

Thank you.

1
  • Will AWS SDK to call 'invoke()' will work here? Commented Apr 19, 2021 at 3:55

3 Answers 3

8

The API Gateway has a maximum integration timeout of 30 seconds (API Gateway Limits), so there is nothing you can do to increase it.

What you could do is accept the request, create and ID and put it in a queue. Then you send an HTTP 202 Message with the request id back to the client. Now a Lambda function can be triggered from the Queue asynchronously that performs the work. It later persists the results of the query somewhere under the request id (maybe only for a period of time). The client can then use the request ID and poll a second API gateway for the status, which is able to return the response once it's present.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Maurice. Do you think AWS SDK to call 'invoke()' will work here? Thank you.
That depends on what you're trying to do - you can start both synchronous as well as asynchronous invocations through the invoke API. A synchronous invoke won't help you with the timeout issue if that's what you're asking.
Does anyone know if this approach is possible using the serverless framework? I can see that the docs mention asynchronous invocation (here: serverless.com/framework/docs/providers/aws/guide/…) but I can't find anything more in the docs about it.
2

You cannot do anything about api Gateway timeout, it is having hard limit of 30 seconds.

A Solution for this is to use alb with aws lambda, alb is not having any timeout limit.

Another option is polling based as suggested in previous answer by @Maurice.

3 Comments

Thanks Pankaj. Do you think AWS SDK to call 'invoke()' will work here? Thank you.
Pankaj, can you elaborate generally how that would work using AWS SKD 'invoke'? Thank you.
There is limit of 15 minutes in lambda and we do lambda.invoke from stepfunction it also waits for response from lambda.
2

As of June 4 2024, it is possible to raise the integration timeout for REST APIs /API Gateway v1/. Here's my answer with an explanation.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.