2
DONTに特定のタグがあるインスタンスを検索しようとしています。BOTT3を使用してDONTにタグがあるインスタンスを見つける方法
たとえば、Fooタグを持たないすべてのインスタンスが必要です。 また、Foo値がBarと等しくないインスタンスも必要です。
import boto3
def aws_get_instances_by_name(name):
"""Get EC2 instances by name"""
ec2 = boto3.resource('ec2')
instance_iterator = ec2.instances.filter(
Filters=[
{
'Name': 'tag:Name',
'Values': [
name,
]
},
{
'Name': 'tag:Foo',
'Values': [
]
},
]
)
return instance_iterator
これは何も返しません:
これは私が今やっているものです。
正しい方法は何ですか?
import boto3
instances = [i for i in boto3.resource('ec2', region_name='ap-southeast-2').instances.all()]
# Print instance_id of instances that do not have a Tag of Key='Foo'
for i in instances:
if 'Foo' not in [t['Key'] for t in i.tags]:
print i.instance_id
が負の比較のためのフィルタがない: – helloV