4

I have 2 instances of the same web application running on port 8080 and 8081. I need to load balance using ALB/CLB. This used to be a simple thing in good old apache web server.The requirement is to load balance the instances below

Instance 1 Web App 1 Port 8080

Instance 1 Web App 2 Port 8081

Instance 2 Web App 1 Port 8080

Instance 2 Web App 2 Port 8081

I am not able to do this with ALB. I have tried creating 2 target groups, one for port 8080 and the other for port 8081. But in the listener rule, I can send the requests to different target groups based the path. But that is not going to load balance the whole site as such. Refer the screenshot

enter image description here

What are my options here ?

Thanks in advance

Community
  • 1
  • 1
Sujith Babu
  • 339
  • 6
  • 19
  • 1
    Why do you have two instances of the *same* webapp on a single VM? – jarmod Feb 27 '19 at 23:34
  • If you are putting multiple instances of the web app on the same instance to save money, this may be a good use case for ECS where you can spin up 4 docker containers on the same instance or distribute them across two/more instances and route them via ALB. – JD D Feb 28 '19 at 00:17
  • or you could put apache on the boxes and have that route traffic between the two web services and then just have the ELB just route traffic between those two instances – JD D Feb 28 '19 at 00:29
  • ECS is a good choice. For now, I want to move the existing architecture in on-premise as is and just replace apache web server load balancer with AWS ELB – Sujith Babu Mar 05 '19 at 22:58

1 Answers1

5

In an ALB, create one target group, adding each instance to the group, twice -- once for each port.

You can register each EC2 instance or IP address with the same target group multiple times using different ports, which enables the load balancer to route requests to microservices.

https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html#registered-targets

Note that this assumes what you are calling "app 1" and "app 2" are in fact the same application, just two different processes, as you described.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427
  • 1
    This worked like a charm. Thanks. Accepting this as the answer. Yes, "app 1" and "app 2" are the same application, but 2 different processes on different ports. Note that for now, I am just trying to replace the existing architecture that has the same apache web server as the load balancer with AWS ELB and my original question was for just that purpose. Eventually, ECS might be a better way to run the same web apps as different processes on the same EC2. – Sujith Babu Mar 06 '19 at 00:44