title: APIgateway + Lamba Test works, but deployed API leads to Lambda timeout
body: <p>I have a Lambda function behind an APIgateway. I am using proxy integration. So when I use the test function of the APIgateway I get a proper response and a 200 status.
  When I use the test function of the Lambda (I use the predefined <em>Amazon API Gateway AWS Proxy</em> testevent) everything is fine and I get a 200 status and the correct result.</p>
  
  <p>However, if I stage the API and then try to access it that way I will get a <em>"Endpoint request timed out"</em> or <em>"Internal server error"</em> depending on my timeout for lambda. Reading the logs I can clearly tell, that the lambda function itself will timeout. </p>
  
  <p>My timeout for the lambda function is usually set to 20 seconds.
  If I set it higher, my lambda function will continue working for abaout five minutes and then exit without an error. Sadly I cant see the result, since APIgateway will always timeout after at most 29 seconds.</p>
  
  <p>I can only guess that there is a difference betwen the request sent by <em>APIgateway tester</em> / <em>lambda tester</em> and the request sent by the <em>stage</em>.</p>
  
  <p>Can someone please enlighten me?</p>
  
  <p>APIgateway execution log:</p>
  
  <pre><code>(ac186ee6-9995-11e9-aa08-19c69016a70d) HTTP Method: GET, Resource Path: /
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Method request path:
  {}
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Method request query string:
  {}
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Method request headers: {Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8, CloudFront-Viewer-Country=DE, CloudFront-Forwarded-Proto=https, CloudFront-Is-Tablet-Viewer=false, CloudFront-Is-Mobile-Viewer=false, User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0, X-Forwarded-Proto=https, CloudFront-Is-SmartTV-Viewer=false, Host=l71vxfeqi.execute-api.eu-central-1.amazonaws.com, Accept-Encoding=gzip, deflate, br, X-Forwarded-Port=443, X-Amzn-Trace-Id=Root=1-5d15f634-d96c0d0f39695f7884dc7c57, Via=2.0 7d0bc7cb3b35ca4f488e655fac219221.cloudfront.net (CloudFront), upgrade-insecure-requests=1, X-Amz-Cf-Id=mNIru4JjDjvndC-EbUKTuR60b9CD_uHeG1hRrxLUTLOd0t5hzTqhJw==, X-Forwarded-For=139.2.1.6, 54.182.239.89, Accept-Language=de,en-US;q=0.7,en;q=0.3, cache-control=max-age=0, CloudFront-Is-Desktop-Viewer=true}
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Method request body before transformations:
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Endpoint request URI: https://lambda.eu-central-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:eu-central-1:908548826170:function:funAsOne/invocations
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Endpoint request headers: {x-amzn-lambda-integration-tag=ac186ee6-9995-11e9-aa08-19c69016a70d, Authorization=***************************************************************************************************************************************************************************************************************************************************************************************************************************553a6e, X-Amz-Date=20190628T111252Z, x-amzn-apigateway-api-id=l71vxfeqi, X-Amz-Source-Arn=arn:aws:execute-api:eu-central-1:908548826170:l71vxfeqi/default/ANY/, Accept=application/json, User-Agent=AmazonAPIGateway_lv17xt01qi, X-Amz-Security-Token=AgoJb3JpZ2luX2VjEBIaDGV1LWNlbnRyYWwtMSJGMEQCIHy9md2iHdQ4EPQmHT9oIzMPljYjRuq7Hq1nWoUhnvgSAiAaaLSRs3v9FJUy1Wl2JhvIe83prHLLwKMKa4mnmVqlASrgAwhbEAAaDDQ3NDI0MDE0NjgwMiIM+FTGP/2q6hBh6HPPKr0D4KW+TSQlaJc4SASsly2jRPCqB5lWlsjmz3WivjwAVtItPVIgUZFrW8uH7tijfkQ4VaQQ3AM32Ilim35r9lgpEnPvsSIcj56k8n+8uPJko5cPQDXjFpFBLkUu5Eq9mjS0KiBEeau0yXk05uy9RQajA4zsF0tir3QHuWMrEblq [TRUNCATED]
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Endpoint request body after transformations: {"resource":"/","path":"/","httpMethod":"GET","headers":{"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Accept-Encoding":"gzip, deflate, br","Accept-Language":"de,en-US;q=0.7,en;q=0.3","cache-control":"max-age=0","CloudFront-Forwarded-Proto":"https","CloudFront-Is-Desktop-Viewer":"true","CloudFront-Is-Mobile-Viewer":"false","CloudFront-Is-SmartTV-Viewer":"false","CloudFront-Is-Tablet-Viewer":"false","CloudFront-Viewer-Country":"DE","Host":"l71vxfeqi.execute-api.eu-central-1.amazonaws.com","upgrade-insecure-requests":"1","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0","Via":"2.0 7d0bc7cb3b35ca4f488e655fac219221.cloudfront.net (CloudFront)","X-Amz-Cf-Id":"mNIru4JjDjvndC-EbUKTuR60b9CD_uHeG1hRrxLUTLOd0t5hzTqhJw==","X-Amzn-Trace-Id":"Root=1-5d15f634-d96c0d0f39695f7884dc7c57","X-Forwarded-For":"139.2.1.6, 54.182.239.89","X-Forwarded-Port":"443","X-Forwarded-Proto":"https"},"multiValueHeaders":{"A [TRUNCATED]
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Sending request to https://lambda.eu-central-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:eu-central-1:908548826170:function:funAsOne/invocations
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Received response. Status: 200, Integration latency: 20045 ms
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Endpoint response headers: {Date=Fri, 28 Jun 2019 11:13:12 GMT, Content-Type=application/json, Content-Length=115, Connection=keep-alive, x-amzn-RequestId=2061f183-3415-4508-b95e-92d2cefffe6b, X-Amz-Function-Error=Unhandled, x-amzn-Remapped-Content-Length=0, X-Amz-Executed-Version=$LATEST, X-Amzn-Trace-Id=root=1-5d15f634-d96c0d0f39695f7884dc7c57;sampled=0}
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Endpoint response body before transformations:
  {
      "errorMessage": "2019-06-28T11:13:12.843Z 2061f183-3415-4508-b95e-92d2cefffe6b Task timed out after 20.02 seconds"
  }
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Lambda execution failed with status 200 due to customer function error: 2019-06-28T11:13:12.843Z 2061f183-3415-4508-b95e-92d2cefffe6b Task timed out after 20.02 seconds. Lambda request id: 2061f183-3415-4508-b95e-92d2cefffe6b
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Gateway response type: DEFAULT_5XX with status code: 502
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Gateway response body:
  {
      "message": "Internal server error"
  }
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Gateway response headers: {Access-Control-Allow-Headers=Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token, Access-Control-Allow-Origin=*, Access-Control-Allow-Methods=DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT}
  (ac186ee6-9995-11e9-aa08-19c69016a70d) Method completed with status: 502
  </code></pre>
  
  <p>Lambda execution log:</p>
  
  <pre><code>11:19:07 START RequestId: d3a4cfd5-2e8f-489d-a5a3-9601adf406a8 Version: $LATEST
  11:19:09 [Fri Jun 28 11:19:09 2019] 127.0.0.1:59760 [301]: /
  11:23:48 END RequestId: d3a4cfd5-2e8f-489d-a5a3-9601adf406a8
  11:23:48 REPORT RequestId: d3a4cfd5-2e8f-489d-a5a3-9601adf406a8 Init Duration: 73.73 ms Duration: 281070.57 ms Billed Duration: 281200 ms Memory Size: 512 MB Max Memory Used: 55 MB 
  </code></pre>
  
  <p><strong>I fixed it:</strong> </p>
  
  <p>This behaviour was due to a redirect loop from "home" to "home".</p>
  
  <p>Adding the following line to wp-setting.php fixed it for me. Sadly this is only a workaround. Maybe someone can hint me to a better fix.</p>
  
  <pre><code>remove_action('template_redirect', 'redirect_canonical');
  </code></pre>