Reputation: 704
How can route a request from API Gateway based towards the lambda functions A/B/C based in the fact that specific header is present or not?
https://api.example.com/prod
if the headers "UserType" is:
guest -> redirect to lambda A
normal -> redirect to lambda B
admin -> redirect to lambda C
I know how only using different URL, e.g:
https://api.example.com/prod
https://api.example.com/dev
Upvotes: 1
Views: 1320
Reputation: 99
It's actually not possible. We can bind only one Lambda function with a specific resource of API Gateway. The headers are accessible as an event parameter within the lambda function itself.
Preferred way would be to create 3 different functions(your business logic's will reside here) within your lambda & based on usertype you can call the function.
And if you really want to make use of three different lambdas, you can make use of invoke method available in aws-sdk. You can refer following link for code syntax & example.
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#invoke-property
2nd method will definitely increase the response time.
Upvotes: 2