AWS: is it possible to map (ELB/ALB) to ELB? - amazon-web-services

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.

Related

Target (Instance on Elastic Beanstalk) is getting removed from AWS target group after deployment or auto-scaling

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

codedeploy --> ASG How it adds instance to --> ELB

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?

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

Attaching a target group of ALB to an Auto-scaling group

We know that in order to attach an Application/Network load balancer for an auto-scaling group, we need to attach the target group(s) to the existing Auto-scaling group in order to distribute the load. In the case of the Classic Load Balancer, we directly attach the load balancer to the ASG but in case of an ALB, we do it through the target groups consisting of targets which can be either an instance, IP or a lambda function.
My question is, are the instances in these target groups defined for an ALB and the instances in ASG different? Or are they the same? If they are the same, then do we have to create a new target group again with targets defined as the EC2 instances in ASG? I can't understand the mapping of instances in target-groups to the instances in ASG. I went through the documentation for attaching a load balancer to an existing ASG, but all it says is to select an existing target group.
Are the instances in these target groups defined for an ALB and the instances in ASG different? Or are they the same?
They are the same.
ELB -> Target Group -> EC2 (without ASG)
ELB -> Target Group -> ASG -> EC2 (with ASG).
Please read the link below for details.
If they are the same, then do we have to create a new target group
again with targets defined as the EC2 instances in ASG
This quote from the AWS document. We need to add ASG to ELB, then AWS takes care of the rest.
When you use your Elastic Load Balancing load balancer with an Auto
Scaling group, it's not necessary to register your EC2 instances with
the load balancer or target group. With Elastic Load Balancing,
instances that are launched by your Auto Scaling group are
automatically registered with the load balancer or target group, and
instances that are terminated by your Auto Scaling group are
automatically deregistered from the load balancer or target group
Ref: https://docs.aws.amazon.com/autoscaling/ec2/userguide/autoscaling-load-balancer.html

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?
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/