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
已提問 4 年前檢視次數 1830 次
1 個回答
0
已接受的答案

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
已回答 4 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南