Wildcard API Gateway domain using $context.domainPrefix to dynamically call Lambdas by name

0

Considering the following scenario where I have multiple customers and each one has it's own sets of lambdas and a custom subdomain. Let's say.

client1.domain -> must call http-client1-lambda
client2.domain -> must call http-client2-lambda

I have reached a limit on the number of custom domains I can create and I want to have now a single one using wildcard and make it dynamically call the respective client lambda using $context.domainPrefix.

I could not find a way to do that.

I don't use any API Gateway specific feature, it can be that ALB or ELB could solve this issue for me, I just use API Gateway because the serverless framework deploys that for me.

2개 답변
1

Haven't tried this myself, but I am thinking you may be able to achieve this using API Gateway and Step Functions, based on this capability announcement - https://aws.amazon.com/about-aws/whats-new/2021/05/amazon-api-gateway-rest-apis-integrates-with-step-funtions-synchronous-express-workflows/#:~:text=You%20can%20now%20create%20Amazon,a%20workflow%20of%20different%20microservices.

From the step function, you can branch out to the different lambdas depending on the client ID that you capture in your API Gateway and pass-on to the Step Function. Worth doing a POC.

If your processing can be asynchronous, then you can receive one primary lambda that receives the request from API Gateway, parses the Client ID and based on that drops the message in a different SQS queue for each Client. You can then have secondary lambdas for each client that get triggered by their respective SQS queue messages and do the processing. If you want to not hard-code the SQS queues in your primary lambda, you can create a look-up table in DynamoDB. That way new clients can be added without having to modify the primary lambda code and redeploy every time a new client is added.

profile pictureAWS
전문가
답변함 2년 전
  • I would need to work with http requests, so I think this approach will add latency to the requests

0

With Application load balancer, you can make use host based routing. (https://aws.amazon.com/premiumsupport/knowledge-center/elb-configure-host-based-routing-alb/ )

That way:-

``

client1.domain -> ALB -----(Rule-1)------> Target group-1 that hosts client1.domain.
client2.domain -> ALB -----(Rule-2)------> Target group-2 that hosts client2.domain.

``

You can have lambda function as as a target, instead of re-writing everything on a EC2 again.

https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html

AWS
답변함 2년 전
  • that could be an option, I'll try it, but I'm afraid we will reach som Target Group limits soon

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

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

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

관련 콘텐츠