List instances in auto scaling group with boto

。_饼干妹妹 提交于 2019-11-30 09:32:47
garnaat

Something like this should work:

>>> import boto
>>> autoscale = boto.connect_autoscale()
>>> ec2 = boto.connect_ec2()
>>> group = autoscale.get_all_groups(['mygroupname'])[0]
>>> instance_ids = [i.instance_id for i in group.instances]
>>> reservations = ec2.get_all_instances(instance_ids)
>>> instances = [i for r in reservations for i in r.instances]

The reason we have to collect the Instance ID's and then call EC2 is that AutoScale only stores a small subset of information about the instances. This would result in the variable instances pointing to a list of Instance objects for each instance in the autoscaling group "mygroupname".

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