API Gateway Dynamic routing

0

My customer has a multi-tenant application that wants to route all tenant traffic to a single endpoint. Based on content in the request header the request would be routed to the appropriate tenant's endpoint similar to a how a Lambda authorizer works but to change routing. The tenant id/route mapping can change over time, so would need to be looked up in something like DynamoDB. What is the best way to accomplish this?

AWS
Kevin_B
gefragt vor 4 Jahren1829 Aufrufe
1 Antwort
0
Akzeptierte Antwort

You can do this using Lambda@Edge using CloudFront. The Lambda function could use a Route 53 hostname in it to make it more resilient and easy to modify the weights + hostnames of DCs.

To add -

If the incoming request doesn't have that specific header, you can let Lambda@Edge do the routing based on the routing_logic. Once the request is mapped to a backend, you would want to stick a cookie (session/persistent) in the browser with that Origin value.

When subsequent requests come to CloudFront, your logic would be like:

{
   IF: 
      Request Header: A
   THEN:
      Go to, Origin = A
}
{
   IF: 
      Request Header: B
   THEN:
      Go to, Origin = B
}

Even for the above snippet that I shared, my vote would be to 'not' hardcode A and B Origin hostnames in Lambda functions and still create R53 failover properties, and use them in there. The advantage is that; if A goes down, the failover property would automatically send the requests to the failover target.

AWS
beantwortet vor 4 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen