Amazon web services 按';标记:组件';:';foo';,或';标记:组件';:';酒吧';
我想在boto中得到一个实例列表,要么有一个foo或bar的“component”标记Amazon web services 按';标记:组件';:';foo';,或';标记:组件';:';酒吧';,amazon-web-services,boto,Amazon Web Services,Boto,我想在boto中得到一个实例列表,要么有一个foo或bar的“component”标记 有没有办法避免发出两个请求并咀嚼对象?这应该可以找到所有实例,这些实例都有一个名为component的标记,其值为foo或bar: import boto.ec2 c = boto.ec2.connect_to_region('us-west-2') reservations = c.get_all_instances(filters={'tag:component':['foo', 'bar']}) 这能
有没有办法避免发出两个请求并咀嚼对象?这应该可以找到所有实例,这些实例都有一个名为
component
的标记,其值为foo
或bar
:
import boto.ec2
c = boto.ec2.connect_to_region('us-west-2')
reservations = c.get_all_instances(filters={'tag:component':['foo', 'bar']})
这能解决你的问题吗?我得到一个空列表。我想这是&,不是吗?文档()说这应该是一个OR。让我试着进行更多的测试。我只是尝试向单个实例添加
组件:foo
标记,然后执行上面的调用,它返回了实例。所以,它似乎是为我做的。
# With boto3
def get_instances_by_tag_value( tag, value):
ec2 = boto3.resource('ec2')
instances = ec2.instances.filter(
Filters=[{'Name': 'tag:' + tag, 'Values': [value]}])
for instance in instances:
print(instance.id, instance.instance_type)
get_instances_by_tag_value('tagname', 'tagvalue') # call function