我可以使用 CloudFormation 将 EC2 实例附加到现有负载均衡器吗
Can I attach an EC2 instance to an existing Load Balancer using CloudFormation
我们通常将实例附加到负载均衡器的方式是在我的 aws 模板中定义负载均衡器时使用 instances 键。无论如何,我可以将 EC2 实例附加到已经存在的负载均衡器吗?
如果您不介意通过 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
间接创建 EC2 实例(如果使用应用程序负载均衡器)属性.
否则,您可以调用 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(例如,使用 AWS SDK for JavaScript 从 Lambda 函数)。
我们通常将实例附加到负载均衡器的方式是在我的 aws 模板中定义负载均衡器时使用 instances 键。无论如何,我可以将 EC2 实例附加到已经存在的负载均衡器吗?
如果您不介意通过 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
间接创建 EC2 实例(如果使用应用程序负载均衡器)属性.
否则,您可以调用 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(例如,使用 AWS SDK for JavaScript 从 Lambda 函数)。