Best practice to deal with 200 statusCode / long running lambda function

I have a lambda function being served through api gateway. The function usually takes about 2.5 minutes to complete. When I run it through apig-test I get a 200 code but obviously no data.

How can I monitor for completion and get the data produced by the function?

What is the best way to deal with this in AWS and Serverless?

Hi, if I’m not mistaken API gateway has a 30 seconds timeout limit. So I think you have a few options:

  1. You can send a request, your lambda puts a task to some queue and returns an operation key. Another lamda triggers (because of the queue) and does your task and saves a result somewhere. Your client’s code from time to time asks about the task status using the operation key. You can avoid using a queue just calling another lambda asynchronously and pass params from the request.
  2. If your client’s code is another server - you can try to use a callback URL. The first lambda puts the request to a queue and returns 202, the second one does the job and calls a callback URL passing a result
1 Like