Search code examples
amazon-web-servicesaws-lambdaaws-api-gateway

How to make an API Gateway trigger call a lambda asynchronously?


I setup my lambda in AWS in the following way:

enter image description here

There is an API Gateway trigger which triggers a Lambda, which in turn is supposed to write to SQS.

The last part doesn't happen. From what I've read, this is because API Gateway invokes lambdas synchronously by default since calling it async-ly sacrifices the ability to return a response from the lambda.

I have also read that nonetheless, it is possible to configure API Gateway to call lambas async: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-integration-async.html

enter image description here

However, it is unclear how to do this when the API Gateway is created by Lambda, as is the case with triggers. There is no clear way of adding additional headers to them.

Is it possible make it do an async invocation?


Solution

  • After digging into it, it seems that API Gateway does not (yet) support async invocations for lambdas in any way for HTTP APIs, it is possible REST APIs.

    Step 1: Create a trigger using the REST configuration

    enter image description here

    Step 2: Disable proxy integration

    Async is explicitly not supported for proxies.

    enter image description here

    Step 3: Add magic header to make lambda async

    enter image description here

    Step 4: Confirm

    To confirm if it worked, look into your destination (in my case SQS) to confirm. enter image description here

    Additionally, your API (when called via API Gateway) should now return an empty page.