title: Catching timeout errors in AWS Api Gateway
body: <p>Since Api Gateway time limit is 10 seconds to execute any request I'm trying to deal with timeout errors, but a haven't found a way to catch and respond a custom message.</p>
  
  <p>Context of the problem: I have a function that takes less than 2 seconds to execute, but when the function performs a cold start sometimes it takes more than 10 seconds creating a connection with DynamoDB in Java. I've already optimize my function using threads but I still cannot keep between the 10-seconds limit for the initial call.</p>
  
  <p>I need to find a way to deliver a response model like this:</p>
  
  <pre><code>{
    "error": "timeout"
  }
  </code></pre>
  
  <p>To find a solution I created a function in Lambda that intentionally responds something after 10 seconds of execution. Doing the integration with Api Gateway I'm getting this response:</p>
  
  <pre><code>Request: /example/lazy
  Status:
  Latency: ms
  </code></pre>
  
  <p>Response Body</p>
  
  <pre><code>{
    "logref": "********-****-****-****-1d49e75b73de",
    "message": "Timeout waiting for endpoint response"
  }
  </code></pre>
  
  <p>In documentation I found that you can catch this errors using HTTP status regex in Integration Response. But I haven't find a way to do so, and it seems that nobody on the Internet is having my same problem, as I haven't find this specific message in any forum.</p>
  
  <p>I have tried with these regex:</p>
  
  <pre><code>.*"message".*
  Timeout.*
  .*"status":400.*
  .*"status":404.*
  .*"status":504.*
  .*"status":500.*
  </code></pre>
  
  <p>Anybody knows witch regex I should use to capture this "message": "Timeout... ?</p>