How can I filter AWS instances using Tag and Value using boto3
?
import boto3
ec2 = boto3.resource('ec2')
client = boto3.client('ec2')
response = client.describe_tags(
Filters=[{'Key': 'Owner', 'Value': 'user@example.com'}])
print(response)
How can I filter AWS instances using Tag and Value using boto3
?
import boto3
ec2 = boto3.resource('ec2')
client = boto3.client('ec2')
response = client.describe_tags(
Filters=[{'Key': 'Owner', 'Value': 'user@example.com'}])
print(response)
You are using the wrong API. Use describe_instances
boto3.client.describe_tags() is universal, but it is tedious to use. because you need to nest and specify the services, tag key name and tag values to filter . i.e.
As @helloV suggested, it is much easier to use describe_instances(). describe_tags is there to allow user to create function to traverse all the services tags.