AWS:boto3获取负载均衡器的所有实例 [英] aws: boto3 get all instances of a load balancers

查看:372
本文介绍了AWS:boto3获取负载均衡器的所有实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下方法获得负载均衡器

I can able to get the load balancers using below

import boto3
elb = boto3.client('elbv2')
lbs = elb.describe_load_balancers()

如何获取实例 lbs

我也该如何获取状态为无效的负载均衡器,因为describe_load_balanacers仅给出状态活动负载均衡。

Also How Can I fetch the load balancers which state is not active as describe_load_balanacers only give state active load balanceres.

推荐答案

经典负载均衡器

使用: client = boto3.client('elb')

然后 describe_load_balancers() 结果包括实例列表:

Then describe_load_balancers() results include a list of instances:

        'Instances': [
            {
                'InstanceId': 'string'
            },
        ],

Application Load Balancer

使用: client = boto3.client('elbv2')

  • Call describe_target_groups() passing in the Load Balancer ARN to obtain a list of Target Groups associated with the Load Balancer
  • Then call describe_target_health() to obtain a list of targets (instances).

以下是示例响应:

{
    'TargetHealthDescriptions': [
        {
            'Target': {
                'Id': 'i-0f76fade',
                'Port': 80,
            },
...

这篇关于AWS:boto3获取负载均衡器的所有实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆