获取Boto3中具有特定标记和值的EC2实例的列表 [英] Get list of EC2 instances with specific Tag and Value in Boto3
本文介绍了获取Boto3中具有特定标记和值的EC2实例的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 boto3
使用标记和值过滤AWS实例?
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)
推荐答案
您使用了错误的API。使用 describe_instances
You are using the wrong API. Use describe_instances
import boto3
client = boto3.client('ec2')
custom_filter = [{
'Name':'tag:Owner',
'Values': ['user@example.com']}]
response = client.describe_instances(Filters=custom_filter)
这篇关于获取Boto3中具有特定标记和值的EC2实例的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文