如何使用python boto3模块查询AWS以获取ELB名称和附加实例? [英] How to query AWS to get ELB names and attached instances to that using python boto3 modules?

查看:246
本文介绍了如何使用python boto3模块查询AWS以获取ELB名称和附加实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用boto3查找代码.我可以分别获取elb名称和InstanceID,但是无法将它们链接在一起以找到ELB名称的附加实例.

I cant find code with boto3. I'm able to get elb name and InstanceID separately but cant link them together to find attached instances to ELB names.

推荐答案

这是我的解决方案,可以使它起作用.谢谢约翰.

This is my solution which I got it to work. Thank you John.

elbList = boto3.client('elb')
ec2 = boto3.resource('ec2')

bals = elbList.describe_load_balancers()
for elb in bals['LoadBalancerDescriptions']:
    print 'ELB DNS Name : ' + elb['DNSName']
    for ec2Id in elb['Instances']:
        running_instances = \
            ec2.instances.filter(Filters=[{'Name': 'instance-state-name'
                                 , 'Values': ['running']},
                                 {'Name': 'instance-id',
                                 'Values': [ec2Id['InstanceId']]}])
        for instance in running_instances:
            print("              Instance : " + instance.public_dns_name);

这篇关于如何使用python boto3模块查询AWS以获取ELB名称和附加实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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