python 使用Python和Boto3获取具有实例ID的实例标记信息

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 使用Python和Boto3获取具有实例ID的实例标记信息相关的知识,希望对你有一定的参考价值。

import boto3

def get_instance_name(fid):
    """
        When given an instance ID as str e.g. 'i-1234567', return the instance 'Name' from the name tag.
        :param fid:
        :return:
    """
    ec2 = boto3.resource('ec2')
    ec2instance = ec2.Instance(fid)
    instancename = ''
    for tags in ec2instance.tags:
        if tags["Key"] == 'Name':
            instancename = tags["Value"]
    return instancename

以上是关于python 使用Python和Boto3获取具有实例ID的实例标记信息的主要内容,如果未能解决你的问题,请参考以下文章