API Gateway timeout gotcha with AWS Lambda
At a company I've been working with, we have a set of some 33 odd or so Lambda functions that are triggered via Amazon's API Gateway. We recently discovered (the hard way!) about a unclearly documented limitation of using API gateway to trigger lambda functions.
Per the Amazon documentation on the API Gateway Limits
Integration timeout 50 milliseconds - 29 seconds for all integration types, including Lambda, Lambda proxy, HTTP, HTTP proxy, and AWS integrations.
This can be somewhat conflicting if your new to lambda like I was, as the UI in Lambda has an option to configure the timeout for up to 5 minutes. What you need to understand is that this timeout is for the function itself. Amazon API gateway is a separate service that requires a response from the lambda function within 29 seconds or you will receive the infamous "Endpoint request timed out" response.
Your options are that you can use one of Amazon's other services like SQS to trigger the lambda function thereby incurring no timeout, but I'm guessing that like us, that would probably require a major overhaul to both your lambda code and what ever service is relying on it.
Luckily, we were able to put our heads together and figure out that even though the API gateway process times out the lambda function still runs (up to the 5 minute limit) it just has no way to return a response when the gateway times out. So we were able to quickly put our heads together and easily refactor existing code to POST to a callback URL. Problem solved!