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?
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
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
Is there a way like assigning a specific tag for the EC2 instances to automatically attached to the load balancer on AWS?
I believe I had done that in the past but unable to find that option now.
Since you say you've done it in the past, I believe you're thinking of a feature offered by EC2 auto-scaling groups (ASGs). ASG is a capability of the EC2 infrastructure that scales machine counts up and down based on workload or maintains a set number of healthy instances always running (destroying and replacing failed instances). When an ASG is attached to a load balancer, the instances controlled by the ASG are automatically registered and deregistered from the balancer.
Amazon EC2 Auto Scaling integrates with Elastic Load Balancing to enable you to attach one or more load balancers to an existing Auto Scaling group. After you attach the load balancer, it automatically registers the instances in the group and distributes incoming traffic across the instances.
https://docs.aws.amazon.com/autoscaling/ec2/userguide/attach-load-balancer-asg.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.
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/