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
demandé il y a 4 ans1830 vues
1 réponse
0
Réponse acceptée

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
répondu il y a 4 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions