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?
By default, Elastic Beanstalk creates an Application Load Balancer for your environment when you enable load balancing with the Elastic Beanstalk console or the EB CLI.
ELB load balancers can span multiple AZs but cannot span multiple regions. That means that if you'd like to create a set of instances spanning both the US and Europe Regions you'd have to create two load balancers and have some sort of other means of distributing requests between the two load balancers.
Elastic Load Balancing supports the following types of load balancers: Application Load Balancers, Network Load Balancers, and Classic Load Balancers. Amazon ECS services can use these types of load balancer. Application Load Balancers are used to route HTTP/HTTPS (or Layer 7) traffic.
The same dedicated load balancer can be used with different environments within the same VPC. Each dedicated load balancer exposes an external CNAME record lb-name.lb.anypointdns.net that resolves to the two or more public IP addresses and internal CNAME internal-lb-name.lb.anypointdns.net.
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).
The way I achieved this in the console for Application load balancer and elastic beanstalk is the following
This allows you to setup dns on ALB-App ("loadbalancer.com") and forward traffic based on rules to different target groups that have instances managed by different beanstalks. Just follow the steps to create a target group for each beanstalk environment and add it to the rules on ALB-App
the result:
"loadbalancer.com/app1" -> ALB-App -> TG-App1 -> Beanstalk Environment 1 instances
"loadbalancer.com/app2" -> ALB-App -> TG-App2 -> Beanstalk Environment 2 instances
Amazon Elastic Beanstalk now support for shared load balancers
11 - Sept-2020
https://aws.amazon.com/blogs/containers/amazon-elastic-beanstalk-introduces-support-shared-load-balancers/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With