Home > Back-end >  Is it possible to return the response from a lambda when using Api gateway with eventbridge?
Is it possible to return the response from a lambda when using Api gateway with eventbridge?

Time:08-27

I have created a micro service architecture which flows as follows:

Api call -> Api gateway -> Eventbridge -> SNS -> Lambda

The reason for this is to use SNS instead of SQS to decouple applications for true serverless compute without the need for lambda to continuously poll sqs, pub sub over push poll.

The trouble is that although the execution is fine and the lambdas run as expected the return received by the user or app is the eventbridge response. I can’t find any docs on how eventbridge handles responses for http requests through API gateway.

Does anyone have any ideas or docs to push me in the right direction.

Thanks!

CodePudding user response:

In your setup it's not possible to have the Lambda response proxied back to the api request initiator, as your client is very much decoupled of the actual request processing.

Almost identical issue was experienced here

You need to rethink the process as a whole:

  • what operation you want to complete via the API request?
  • does the processing of the request really need to be asynchronous (= does it take long time to complete?)
  • can you handle the request with a Lambda function, delegate to sns from there and finally generate desired response back to the client?

CodePudding user response:

So as it turns out the answer is yes and no for anyone coming across this in the future.

With the current setup another database is required and the responses can be inserted into it with a transaction ID. This transaction ID can be generated by the client during the request so a subsequent call to find the response in the table can be made.

Alternatively Websocket or GraphQL api’s or would allow for asynchronous invocation if really depends on your use case and accepted complexity.

Thanks for everyone’s inputs!

  • Related