我在 python 3.5.2 中使用 boto 3 试图描述 ec2 图像。文档说可用的过滤器之一是“is-public”:
is-public - A Boolean that indicates whether the image is public.
但是 Filter 语法需要一个字符串列表 - 而且只是一个字符串列表 - 作为值。如果我尝试传递一个 bool 值,它会给我一个类型错误:
Invalid type for parameter Filters[0].Values[0], value: False, type: <class 'bool'>, valid types: <class 'str'>
我的代码:
response = session.client("ec2").describe_images(
Filters=[
{'Name': 'is-public',
'Values': [False],
},
当 bool 过滤器只接受字符串时,我该如何传递它?
谢谢... 账单
最佳答案
这对我有用...使用小写。
ami_filter = [{"Name": "platform", 'Values': ["windows"]},
{"Name": "virtualization-type", 'Values': ["hvm"]},
{"Name": "image-type", 'Values': ["machine"]},
{"Name": "architecture", 'Values': ["x86_64"]},
{"Name": "state", 'Values': ["available"]},
{"Name": "is-public", 'Values': ['false']}]
ami_owners = ['amazon']
results = client.describe_images(Filters=ami_filter, Owners=ami_owners)
关于python-3.x - 如何使用 bool 值的 boto3 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51108391/