Search code examples
amazon-web-servicesswaggerload-balancingamazon-ecsamazon-elb

target group for multiple containers load balancer AWS


I have 3 containers deployed on ecs and traffic is distributed by an application load balancer, swagger on this individual containers can be accessed via e.g 52.XX.XXX.XXX/swagger.

I need the services to be accessed via for e.g:

52.XX.XXX.XXX/users/swagger
52.XX.XXX.XXX/posts/swagger 
52.XX.XXX.XXX/comments/swagger

I've tried add the following the loadbalancer rules

PATH /users* or /users/
PATH /posts* or /posts/
PATH /comments* or /comments/

I get a 404 error when i visit the load balancer dns for example myapp-lb-4283349.us-east-2.elb.amazonaws.com/users/swagger


Solution

  • You can't achieve that with AWS Load Balancer alone. AWS LB doesn't re-route traffic based on paths. They just forwards the incoming traffic to origin.

    Your service should be accessible via 52.XX.XXX.XXX/user/swagger 52.XX.XXX.XXX/posts/swagger etc. in order for Load Balancer to forward it. You can't forward (or re-route) your traffic from Load Balancer like this:

    LB_URL/user/swagger -> IP/swagger
    

    The missing /user/ part is not something Load Balancer can do for you. Update your application itself and add specific routes which you want to listen on.