AWS Load Balancer to route traffic to one target group with multiple microservices

10,774

This is exactly what an Application Load Balancer is designed to do.

You can create multiple Target Groups. Each target group has:

  • A name
  • A target (eg HTTP on port 8080)
  • Health Check configuration to determine whether the target(s) are healthy

So, you would create one Target Group for each app you are running.

You can then associate Amazon EC2 instances with each Target Group. In your case, if everything is running on a single Amazon EC2 instance, you can associate the same instance with all target Groups.

Then, create the Application Load Balancer (or associate the Target Groups to an existing Application Load Balancer).

In the Application Load Balancer configuration, go to the Listeners tab and add rules that send a particular path (eg /users) to a particular target group.

See:

Share:
10,774

Related videos on Youtube

Nilamber Singh
Author by

Nilamber Singh

**Always thriving to learn.**

Updated on June 04, 2022

Comments

  • Nilamber Singh
    Nilamber Singh over 1 year

    I have ALB which listens to HTTP traffic on port 80, i have added a target-group in ALB listeners which consists of a single EC2 machine. My EC2 instance runs multiple microservices on different ports for eg. App1 runs on 8080 , App2 on 8001, App3 on 8004 so on... EC2 listens on port 80 again for any incoming requests through ALB. I want to do a path based routing for incoming traffic to EC2 to different app ports based on the path for example,

    "/users" -> app on 8080 ; "/get/info" -> 8001 etc

    . Is there a way to achieve it? Or any better way to do what i'm trying ? Right now i have done routing based on ip-tables to route traffic from port 80 of EC2 to single port i.e 8080, but that serves only 1 of my many microservices. How can i configure it to serve all of them?

  • Nilamber Singh
    Nilamber Singh over 4 years
    I have only one target group which is has the EC2 instance that's running all the apps, so ALB will route its traffic to the only target group. I want to segregate the requests based on path to route the traffic to diifferent ports in same target group
  • John Rotenstein
    John Rotenstein over 4 years
    You will need to create one target group per app. You can register an instance with multiple target groups. You then use rules to configure which path will use which target group, which means that a given path will be routed to a particular port.
  • Babar Baig
    Babar Baig almost 4 years
    I have exactly the same problem. I am doing the same @JohnRotenstein is suggesting. I have 2 listener rules and 2 target groups pointing to the same EC2 instance. Health checks are passed but unfortunately, ALB only routes traffic to 1 target group. What can be the root cause here? Anyone?
  • Babar Baig
    Babar Baig over 3 years
    @Kunal yes. my issue was resolved using path-based routing and Nginx.