按标记键过滤效果很好:
ec2.get_all_instances(filters={'tag-key': 'MachineType'})
如何按键和值过滤?
"MachineType=DB"
答案 0 :(得分: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