gpt4 book ai didi

python-3.x - 获取 Boto3 中具有特定标签和值的 EC2 实例列表

转载 作者:行者123 更新时间:2023-12-02 16:25:07 25 4
gpt4 key购买 nike

如何使用 boto3 使用标签和值过滤 AWS 实例?

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

import boto3

client = boto3.client('ec2')

custom_filter = [{
'Name':'tag:Owner',
'Values': ['user@example.com']}]

response = client.describe_instances(Filters=custom_filter)

关于python-3.x - 获取 Boto3 中具有特定标签和值的 EC2 实例列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48072398/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com