How can a single method in the API Gateway console invoke two Lambda functions ?

0

This is the workflow of my Serverless API management system for clients

Go through the step 5 and step 6, I want to have a single method under a resource in the API gateway console. When the request comes to this method, this method in API gateway console has to invoke two lambda functions, one to check the clients available credits and another lambda function or REST endpoint processing the actual request.

My question is, How can a single method in the API Gateway console invoke two Lambda functions, one to check the client's available credits and another to process the actual request? Is it possible to configure a single method in the API Gateway console to work with this process?

2 Answers
0

Hi,

  1. you should check if you can replace the 1st lambda with an API gateway validator: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-request-validation.html

  2. Otherwise, if you need to keep both Lambdas: use a Lambda Authorizer https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html and then call your second functional Lambda via the regular binding GTW -> Lambda

profile pictureAWS
EXPERT
answered a year ago
  • Hello, Thats seems a good approach for handling one lambda function as API Gateway Authorizer, but what if I want another third lambda function to fill logging table which has to run when the main endpoint request is processed. How can I do that ? In a single Method in API Gateway ?

  • For your 3rd Lambda logging API activity, a common pattern is to push the log message to an Amazon SQS queue and have the 3rd Lambda receive and process those from SQS as asynchronous events. You could also log authorization activity from the 1st Lambda using the same method.

0

Hi,

Another option is to instead have an api gateway with an integration to a step function.

https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-api-gateway.html

It is still good practice to do validations via lambda authorizers and then invoke a step function containing as many states as lambda functions.

Hope it helps ;)

profile picture
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions