我在AWS上有几个与同一IAM角色关联的实例。我正在寻找编写一个返回这些实例的代码。
从此文档:http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html,我看到有一个可用的过滤器iam-instance-profile.arn
。我只是不确定我会如何去使用它,或者如果这是我应该使用的。通过与boto关联的IAM角色过滤ec2实例
这是一个例子,其中实例被标签过滤。
conn = boto.ec2.connect_to_region('ap-southeast-1')
reservations = conn.get_all_instances(filters={"tag:Name": "my-instance-1"});
for reservation in reservations:
instance = reservation.instances[0]
我想做类似的事情,除了IAM角色作为过滤器。
另一件事 - 上面的例子conn.get_all_instances(filters={"tag:Name": "my-instance-1"});
返回保留。我希望获得这些实例,而不必通过预订来获取它们。例如:conn.get_only_instances(instance_ids=['i-cc186913'])
会将实例返回给我。
什么是最好的方式,我可以有一个过滤器(IAM角色)并返回ONLY实例(没有通过保留获得它们)?
谢谢!这样做的工作:) –