Search code examples
amazon-web-servicesamazon-ec2amazon-elastic-beanstalkelastic-load-balancer

Load balancing across different Elastic Beanstalk applications


In my AWS environment there are some load balanced / autoscaled Elastic Beanstalk applications.

I would like to have a load balancer in front of them, so any request to http://loadbalancer.com/app1 is routed to the first Elastic Beanstalk app, http://loadbalancer.com/app2 to the second and so on.

I tried to set up an application load balancer with different listeners routing to different target groups. Unfortunately my solution is not ideal, because the target groups are bound to a fixed set of EC2 instances, while I want them to be associated to an environment where instances are created or destroyed on demand

I haven't still found a way of binding an application load balancer's listener to an auto scaling group.

Is there a way of achieving what I want?


Solution

  • I just managed to do it, following the instructions in this article https://aws.amazon.com/blogs/devops/introducing-application-load-balancer-unlocking-and-optimizing-architectures/

    the steps:

    1) create a new target group

        aws elbv2 create-target-group --name <target_group_name> --protocol HTTP --port 80 --vpc-id <vpc_id> 
    

    2) bind your target group to the autoscaling group associated to the app

        aws autoscaling attach-load-balancer-target-groups --auto-scaling-group-name <id_of_the_autoscaling_group> --target-group-arns "<new_target_group_arns>"
    

    3) create a new rule in the main application load balancer, that routes the desired path to the right application (this can be done through the UI).