【发布时间】:2017-08-11 06:38:03
【问题描述】:
我有几个弹性负载均衡器。我希望动态查找与属于 ELB 目标组的 EC2 实例关联的公共 IP 地址。我以前可以使用以前版本的 ELB 来做到这一点,因为每个 ELB 都会列出实例 ID。现在看来,他们不是。任何线索都会很棒!
【问题讨论】:
标签: python amazon-web-services amazon-ec2 boto3 amazon-elb
我有几个弹性负载均衡器。我希望动态查找与属于 ELB 目标组的 EC2 实例关联的公共 IP 地址。我以前可以使用以前版本的 ELB 来做到这一点,因为每个 ELB 都会列出实例 ID。现在看来,他们不是。任何线索都会很棒!
【问题讨论】:
标签: python amazon-web-services amazon-ec2 boto3 amazon-elb
正如How to query AWS to get ELB names and attached instances to that using python boto3 modules? 上的回答:
Application Load Balancer 有多个目标组。实例上的端口已注册到目标组。
似乎列出目标组中实例的唯一命令是 describe_target_health(),它返回 instance 和 port(因为一个实例可以服务多个目标):
{
'TargetHealthDescriptions': [
{
'Target': {
'Id': 'i-0f76fade',
'Port': 80,
},
'TargetHealth': {
'Description': 'Given target group is not configured to receive traffic from ELB',
'Reason': 'Target.NotInUse',
'State': 'unused',
},
},
{
'HealthCheckPort': '80',
'Target': {
'Id': 'i-0f76fade',
'Port': 80,
},
'TargetHealth': {
'State': 'healthy',
},
},
],
'ResponseMetadata': {
'...': '...',
},
}
【讨论】:
对于那些仍在寻找解决方案的人,我已经为此制作了一个python脚本,代码在github上可用。
【讨论】: