Python boto:过滤标签和值

问题描述 投票:1回答:1

按标签键过滤工作正常:

ec2.get_all_instances(filters={'tag-key': 'MachineType'})

如何按键和值过滤?

"MachineType=DB"
python amazon-web-services boto boto3
1个回答
1
投票

表决

ec2.get_all_instances(filters={"tag:MachineType" : "DB"})

Boto3

import boto3

ec2 = boto3.resource('ec2')
inst_filter = [{'Name':'tag: MachineType', 'Values':['DB']}]
insts = list(ec2.instances.filter(Filters=inst_filter))
for inst in insts:
  print inst.id
© www.soinside.com 2019 - 2024. All rights reserved.