Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 按';标记:组件';:';foo';,或';标记:组件';:';酒吧';_Amazon Web Services_Boto - Fatal编程技术网

Amazon web services 按';标记:组件';:';foo';,或';标记:组件';:';酒吧';

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']}) 这能

我想在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']})

这能解决你的问题吗?

我得到一个空列表。我想这是&,不是吗?文档()说这应该是一个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