Lambda Gateway API Response

I use the Gateway-to-Lambda API for several microservices, but in at least one case, the service will take 20-30 seconds, so in such cases I would like to send an immediate response to the client, something like:

status: 200 message: { progressId: 1234 } 

and then allow the Lambda Function to continue (and periodically update the "processId" somewhere available to the client. The problem is that if you call context.succeed() , context.fail() or context.done() , which, apparently, the lambda functions are stopping from further execution, and yet this is the only way I know to flush the stdout buffer back to the API gateway.

This led me to a second approach, which I have not yet tried to solve (and for simplicity I would like to avoid), which includes an API gateway that calls the Responder function lambda, which then works asynchronously with Microservice and then immediately responds to the gateway API

I tried to illustrate these two parameters in the sketch format below. I would like to hear how someone was able to solve this problem.

two approaches

+7
source share
3 answers

Gateway APIs currently require AWMS Lambda integration to be synchronous. If you want an asynchronous call to your Lambda function, you have 2 options:

  • Call Lambda asynchronously, either with AWS integration invoking InvokeAsync on Lambda, or using an intermediate service such as SNS or Kinesis to start the Lambda function.

  • You are diagram # 2, using a Lambda synchronous call to initiate an asynchronous call.

+6
source

As of April 2016, you can create asynchronous Lambda execution through an API gateway using AWS Service Proxy. See http://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-lambda.html

+4
source

You can send an X-Amz-Invocation-Type header, it supports asynchronous calls using the Event value

You can request asynchronous execution by specifying the event as InvocationType

http://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestSyntax

In addition, if you cannot send it through your microservice, you can configure this header for default transmission using the Execute method β†’ Integration request β†’ HTTP headers in the API gateway resource

This worked for me in the micro-service -> API Gateway -> Lambda script, as indicated in the question.

+2
source

Source: https://habr.com/ru/post/1236575/


All Articles