Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 596
Michele Da Ros Avatar asked Jan 23 '17 13:01

Michele Da Ros


People also ask

Does Elastic Beanstalk use application load balancer?

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.

Can an elastic load balancing span across multiple regions?

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.

What are the three types of elastic load balancing?

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.

Can one use the same dedicated load balancer for different environments in a VPC?

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.


3 Answers

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).

like image 186
Michele Da Ros Avatar answered Oct 21 '22 10:10

Michele Da Ros


The way I achieved this in the console for Application load balancer and elastic beanstalk is the following

  1. Create new target group (TG-App1)
  2. Attach TG-App1 to your beanstalk environments auto scale group. Now you will have both the beanstalk created target group and TG-App1 attached and both will now update with the instances.
  3. Create new application load balancer (ALB-App)
  4. Create ALB-App rules forwarding to TG-App1 (ex: PATH: /app1/* -> FORWARD: TG-App1)
  5. Update the beanstalk environment instance security group to allow traffic from ALB-App's security group on port 80. (you will have 2 port 80 rules now, 1 for ALB-App and 1 for the default beanstalk load balancer security group)

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

like image 6
C Rudolph Avatar answered Oct 21 '22 11:10

C Rudolph


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/

like image 1
Mahesh_Loya Avatar answered Oct 21 '22 11:10

Mahesh_Loya