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
preguntada hace 4 años1829 visualizaciones
1 Respuesta
0
Respuesta aceptada

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
respondido hace 4 años

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas