Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS API Gateway proxy with AWS Lambda as middle ware

I would like to use you AWS API Gateway as a single entry point to my backend which will proxy (redirect) request to different microservices based on URL prefix. However before to do proxy it would be nice to have lambda which may check requests and make a decision if allowed to make proxy or it's better to make a response imidiatly, so, in another word, I would like to have AWS lambda as middleware. Is it possible to do?

like image 332
Bizon4ik Avatar asked May 30 '26 22:05

Bizon4ik


1 Answers

Short answer

Yes, but don't do it. There are other solutions.

Explanation why you shouldn't do it

You can use a lambda in between your containers and API gw but using a lambda as a 'middleware' is an antipattern, you will have to pay double by making your lambda wait on your microservices response.

Other solutions

  • If you want to handle authentication or check headers and cookies you should use a lambda authorizer.

  • For your use-case you can make use of an application loadbalancer. That can do path redirects to different target groups. https://aws.amazon.com/premiumsupport/knowledge-center/elb-achieve-path-based-routing-alb/

  • It might make sense in having a library that is shared by the different microservices that does the early response or request checking.

Not sure what is your real goal and use case but if you elaborate more on what you'd like to achieve, I might can help.

like image 131
Lucasz Avatar answered Jun 02 '26 12:06

Lucasz