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개 답변
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
전문가
답변함 일 년 전
  • 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
전문가
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠