【问题标题】:Find EC2 Instances belonging to specific Target Group with Boto3使用 Boto3 查找属于特定目标组的 EC2 实例
【发布时间】:2017-08-11 06:38:03
【问题描述】:

我有几个弹性负载均衡器。我希望动态查找与属于 ELB 目标组的 EC2 实例关联的公共 IP 地址。我以前可以使用以前版本的 ELB 来做到这一点,因为每个 ELB 都会列出实例 ID。现在看来,他们不是。任何线索都会很棒!

【问题讨论】:

    标签: python amazon-web-services amazon-ec2 boto3 amazon-elb


    【解决方案1】:

    正如How to query AWS to get ELB names and attached instances to that using python boto3 modules? 上的回答:

    Application Load Balancer 有多个目标组。实例上的端口已注册到目标组。

    似乎列出目标组中实例的唯一命令是 describe_target_health(),它返回 instanceport(因为一个实例可以服务多个目标):

    {
        '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': {
            '...': '...',
        },
    }
    

    【讨论】:

      【解决方案2】:

      对于那些仍在寻找解决方案的人,我已经为此制作了一个python脚本,代码在github上可用。

      【讨论】:

      • 这很整洁。谢谢
      猜你喜欢
      • 2021-05-09
      • 2016-07-29
      • 1970-01-01
      • 1970-01-01
      • 2017-05-05
      • 2017-02-23
      • 2021-05-17
      • 1970-01-01
      • 2018-03-11
      相关资源
      最近更新 更多