aws: boto3 get all instances of a load balancers

感情迁移 提交于 2019-12-07 16:27:06

问题


I can able to get the load balancers using below

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

How to get the instances of the lbs.

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


回答1:


Classic Load Balancer

Use: client = boto3.client('elb')

Then describe_load_balancers() results include a list of instances:

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

Application Load Balancer

Use: 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).

Here is a sample response:

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


来源:https://stackoverflow.com/questions/51241012/aws-boto3-get-all-instances-of-a-load-balancers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!