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?
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
Create new target group (TG-App1)
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.
Create new application load balancer (ALB-App)
Create ALB-App rules forwarding to TG-App1 (ex: PATH: /app1/* -> FORWARD: TG-App1)
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
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/
Related
Background:
I have an ALB & Elastic Beanstalk running. I have configured my ALB as a Shared Load Balancer in my Elastic Beanstalk. Also, I have registered the instance of my Elastic Beanstalk as a target in Target Group on same ALB.
Problem:
After deployment or due to auto-scaling, instance gets added/removed from Elastic Beanstalk and this is causing deregistering of target from my target group.
Query
How can we prevent this ?
Or do we have any solution so that newly added instance of EB gets automatically registered to my Target Group of same ALB ?
You can bind autoscaling group of elastic beanstalk environment to your target group which is associated to your loadbalancer.
Go to EC2 > Auto Scaling groups
In detail of Auto Scaling group there is Load balancing section > click on Edit
There you can select your target group
I use AWS Code Deploy and Auto-Scale Groups i.e. blue/green deployment.
I have separately created Elastic Load Balancer and Target group that points to EC2s and not to above ASG.
It seems new deployment seems to be able to add/remove instances from Elastic Load Balancer perfectly fine without any relation of Elastic Load Balancer/Target group to ASG?
How is this possible?
How to setup Load balancing in EC2(wm where our services .war/.db are deployed into diff EC2 vm) in aws even after setting the Auto scaling & ELB managed service in AWS?
If you already set the Auto scaling group and ELB, maybe you're asking how to configure the routing algorithm of the load balancing? Default is round robin:
https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/how-elastic-load-balancing-works.html
Or you're asking how to plug ec2 instances to the configured ELB, and then, as Asri said, put the ec2 instances in a target group, and attach the target group to the load balancer.
You can create Application load balancer attached to a target group which contains your EC2 vms: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/application-load-balancer-getting-started.html
ELB: Elastic Load Balancer
ALB: Application Load Balancer
I am trying to map elb/alb on aws to another elb (ex: http://my-elb-domain.com),
elb/alb -> elb
in alb: I didn't find a way to register elb as targets.
in elb: only maps to instances
This is not possible.
Both the Classic Load Balancer and Target Groups for the Application Load Balancer only accept Amazon EC2 instances as targets.
Explanation
We have found a roundabout way to accomplish this via the AWS CLI, and are currently using it in production to route traffic. Note that the solution below ends up routing to the same instances behind an ELB, but not through the ELB itself. Here's how it works:
When created an elastic beanstalk environment comes with an automatically generated autoscaling group
An auto-scaling group can be attached to up to 10 target groups via the CLI
That target group can be the direct target of an ALB
Visual Flow
Traffic -> ALB -> Target Group -> Autoscaling Group -> Same Instances ELB Points To
Setup Instructions
Create an Elastic Beanstalk application
Get the name of the Autoscaling group generated for the Elastic Beanstalk app
Create a target group (with no targets), save the ARN for the target group.
Create your ALB, setting its target to the target group create in step #3
Attach the target group to your Autoscaling group via the AWS CLI
aws autoscaling attach-load-balancer-target-groups --auto-scaling-group-name {AutoScalingGroupName} --target-group-arns {TargetGroupARN}
No. You can't map one ELB to another ELB directly.
I have the following situation:
I have 1 Rails App that has 2 domains, each of these domains has multiple/dynamical subdomains.
This app is in AWS using a load-balanced Elastic Beanstalk.
What i need is that those 2 domains that points to my single Rails App to work under SSL in port 443.
But since Elastic Beanstalk has only one load balancer, I can only use one single SSL certificate on port 433 :(
Using a UCC SSL certificate won't be the solution because i need each domain certificate to be wildcard, so the dynamic subdomains will also work.
Any thoughts about how to get multiple Load Balancers playing nicely with an Elastic Beanstalk Environment?
Best.
To add multiple Elastic Load Balancers (ELB) to an Elastic Beanstalk (EB) application, you need to add the additional ELB to the auto scaling group of the EB app.
On the command line
The easiest way to achieve this is through the AWS CLI (https://aws.amazon.com/cli/):
aws autoscaling attach-load-balancers --auto-scaling-group-name <SG_NAME> --load-balancer-names <ELB_NAME>
In the AWS Console
Of course this can be done in the AWS Console, too:
Go to EC2 > Auto Scaling > Auto Scaling Groups
select the group you want to add the elb to
Select the Details Tab
Edit-Button on the top right
Use the Autocompletion in the Load Balancers field to add your load balancer
Save
For your convenience, you can see where you need to click for all of the 5 steps (don't forget to save!)
For me this works also on eb-generated auto scaling groups (Region: eu-central-1).
This might not have been available at the time of the question, but it is now.
It's a tough one with Elastic Beanstalk as they have a cookie cutter way of deploying your app and if it's not in their options then you have either "hack it" or just go with a completely different solution using EC2 or plain cloud servers.
One thing you can try is creating another ELB with the certificate of the second domain (and subdomains) and point it to your Elastic Beanstalk Instance. If you go to the ELB console you should be able to see the ELB for the first domain. Then, you can create your second domain based on the first domain.
Hope it helps.
I think that the best solution for your problem is to have multiple domains on the same SSL certificate and then assign that certificate to your ELB environment.
(you can have wildcards, maybe that wasn't available at the time the question was asked)
You don't need extra load balancers.
This worked for me,
First, create the load balancer
aws elb create-load-balancer --load-balancer-name my-load-balancer --listeners "Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=80" "Protocol=HTTPS,LoadBalancerPort=443,InstanceProtocol=HTTP,InstancePort=80,SSLCertificateId=arn-of-certificate" --subnets eb-subnet-of-primary-elb --security-groups sg-of-primary-elb
Then, attach load balancer to primary auto scaling group of EB env
aws autoscaling attach-load-balancers --auto-scaling-group-name asg-name-of-primary-asg-in-eb --load-balancer-names my-load-balancer
One more thing to be aware of is that EBS created instances need to allow your custom ELB to talk to them.
You need to create INBOUND rule in your EBS auto-created security group (with description SecurityGroup for ElasticBeanstalk environment) to allow TCP:80 access. I had my custom ELBs in a different security group so I specified that sg-**** ID as the source.