如何使用boto3基于InstanceId检索实例名称?
connection = boto3.resource('ec2')
instances = connection.instances.filter(InstanceIds=[instanceid])
for instance in instances:
instance_name=???
答案 0 :(得分:3)
您需要获取Name
标记:
def get_name(instance):
for tag in instance.tags:
if tag['Key'] == 'Name':
return tag['Value']