Load balancing across different Elastic Beanstalk applications

有些话、适合烂在心里 提交于 2019-12-18 02:48:37

问题


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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/41807676/load-balancing-across-different-elastic-beanstalk-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!