The way we usually attach instances to a Load Balancer is by using the instances key while defining the load balancer in my aws template. Is there anyway that I can attach an EC2 instance to a Load Balancer that already exists?
Amazon EC2 Auto Scaling provides you with the option of attaching one or more EC2 instances to your existing Auto Scaling group. After an instance is attached, it is considered part of the Auto Scaling group.
Q: Does AWS CloudFormation support Amazon EC2 tagging? Yes. Amazon EC2 resources that support the tagging feature can also be tagged in an AWS template.
To connect using the Amazon EC2 console, the instance must have a public IPv4 address. If the instance does not have a public IP address, you can connect to the instance over a private network using an SSH client or the EC2 Instance Connect CLI.
If you don't mind creating the EC2 instance indirectly through an AWS::AutoScaling::AutoScalingGroup
(e.g., with a DesiredCapacity
of 1), you could automatically attach the EC2 instance to an existing ELB using the LoadBalancerNames
(or TargetGroupARNs
if using an Application Load Balancer) property.
Otherwise, you can call the RegisterInstancesWithLoadBalancer
/ DeregisterInstancesFromLoadBalancer
APIs manually, either directly from the EC2 instance (e.g., from a UserData
script using the AWS CLI), or using a Custom Resource (e.g., using the AWS SDK for JavaScript from a Lambda function).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With