title: How to invoke Lambda asyncronously from API Gateway?
body: <p>As per <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-lambda.html" rel="nofollow noreferrer">here</a>, I believe that setting a header of <code>X-Amz-Invocation-Type: Event</code> should set my Lambda invocation to be asynchronous.</p>
  
  <p>However, by putting a <code>import time;time.sleep(5000)</code> at the beginning of my Lambda function, and sending requests to my API Gateway, I observe that:</p>
  
  <pre><code>$ aws apigateway get-integration --rest-api-id &lt;api-id&gt; \
      --resource-id &lt;resource-id&gt; \
      --http-method POST | jq -r '.requestParameters'
  {
    "integration.request.header.X-Amz-Invocation-Type": "'Event'"
  }
  $ aws apigateway get-integration --rest-api-id &lt;api-id&gt; \
      --resource-id &lt;resource-id&gt; \
      --http-method POST | jq -r '.uri'
  arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:&lt;account-id&gt;:function:[...]Lambda-4HOA0ZSFAYCI/invocations
  $ curl https://&lt;api-id&gt;.execute-api.us-east-1.amazonaws.com/LATEST/&lt;path&gt; -d '{}'
  {"message": "Endpoint request timed out"}
  
  [here I removed the sleep from my lambda function and made it return immediately]
  
  $ curl https://&lt;api-id&gt;.execute-api.us-east-1.amazonaws.com/LATEST/&lt;path&gt; -d '{}'
  {"body": "Request OK", "headers": {"Content-Type": "application/json"}, "statusCode": 200}
  </code></pre>
  
  <p>Assuming that the documentation is accurate, my best guess is that I've misconfigured the Integration somehow - perhaps the <code>"'Event'"</code> is incorrect and it should be <code>"Event"</code>? I'm pretty sure the single-quotes are required, however, to demarcate a static value (as opposed to value parsed from the request). In particular, I suspect that my <code>responseParameters</code> are not right:</p>
  
  <pre><code>$ aws apigateway get-integration --rest-api-id &lt;api-id&gt; \
      --resource-id dzv1zj \
      --http-method POST | jq -r '.integrationResponses'
  {
    "200": {
      "responseTemplates": {
        "application/json": null
      },
      "statusCode": "200"
    }
  }
  </code></pre>
  
  <p>Should <code>null</code> there be some <a href="http://velocity.apache.org/engine/devel/vtl-reference.html" rel="nofollow noreferrer">VTL</a> that staticly returns a <code>200 OK</code>?</p>
  
  <p>As for alternatives: I see that <code>invoke-async</code> is <a href="https://docs.aws.amazon.com/lambda/latest/dg/API_InvokeAsync.html" rel="nofollow noreferrer">deprecated</a>. I'd really rather not go to the overhead of going <code>API Gateway -&gt; SNS -&gt; Lambda</code>.</p>
  
  <p>EDIT: Here are the logs from calling the API via the "Test" option on the console:</p>
  
  <p>Execution log for request test-request</p>
  
  <pre><code>Wed Mar 07 17:24:57 UTC 2018 : Starting execution for request: test-invoke-request
  Wed Mar 07 17:24:57 UTC 2018 : HTTP Method: POST, Resource Path: /&lt;path&gt;
  Wed Mar 07 17:24:57 UTC 2018 : Method request path: {}
  Wed Mar 07 17:24:57 UTC 2018 : Method request query string: {}
  Wed Mar 07 17:24:57 UTC 2018 : Method request headers: {}
  Wed Mar 07 17:24:57 UTC 2018 : Method request body before transformations: {"abc":"def"}
  Wed Mar 07 17:24:57 UTC 2018 : Endpoint request URI: https://lambda.us-east-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:us-east-1:&lt;account-id&gt;:function:[...]Lambda-4HOA0ZSFAYCI/invocations
  Wed Mar 07 17:24:57 UTC 2018 : Endpoint request headers: {X-Amz-Date=20180307T172457Z, x-amzn-apigateway-api-id=&lt;api-id&gt;, Accept=application/json, User-Agent=AmazonAPIGateway_&lt;api-id&gt;, Host=lambda.us-east-1.amazonaws.com, X-Amz-Content-Sha256=2c3fbda5f48b04e39d3a87f89e5bd00b48b6e5e3c4a093de65de0a87b8cc8b3b, X-Amzn-Trace-Id=Root=1-5aa02069-8670eb5d98dbc4ade9df03d8, x-amzn-lambda-integration-tag=test-request, Authorization=**********************************************************************************************************************************************************************************************************************************************************************************************************************************************bfe3de, X-Amz-Source-Arn=arn:aws:execute-api:us-east-1:&lt;account-id&gt;:&lt;api-id&gt;/null/POST/&lt;path&gt;, X-Amz-Invocation-Type=Event, X-Amz-Security-Token=[REDACTED] [TRUNCATED]
  Wed Mar 07 17:24:57 UTC 2018 : Endpoint request body after transformations: {"abc":"def"}
  Wed Mar 07 17:24:57 UTC 2018 : Sending request to https://lambda.us-east-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:us-east-1:&lt;account-id&gt;:function:[...]Lambda-4HOA0ZSFAYCI/invocations
  Wed Mar 07 17:24:57 UTC 2018 : Received response. Integration latency: 43 ms
  Wed Mar 07 17:24:57 UTC 2018 : Endpoint response body before transformations: 
  Wed Mar 07 17:24:57 UTC 2018 : Endpoint response headers: {x-amzn-Remapped-Content-Length=0, Connection=keep-alive, x-amzn-RequestId=75501cbf-222c-11e8-a1fc-2b19f19a9429, Content-Length=0, Date=Wed, 07 Mar 2018 17:24:57 GMT, X-Amzn-Trace-Id=root=1-5aa02069-8670eb5d98dbc4ade9df03d8;sampled=0}
  Wed Mar 07 17:24:57 UTC 2018 : Method response body after transformations: 
  Wed Mar 07 17:24:57 UTC 2018 : Method response headers: {X-Amzn-Trace-Id=sampled=0;root=1-5aa02069-8670eb5d98dbc4ade9df03d8, Content-Type=application/json}
  Wed Mar 07 17:24:57 UTC 2018 : Successfully completed execution
  Wed Mar 07 17:24:57 UTC 2018 : Method completed with status: 200
  </code></pre>