python boto3将IAM角色附加/替换为ec2

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python boto3将IAM角色附加/替换为ec2相关的知识,希望对你有一定的参考价值。

我找不到通过boto3将IAM角色附加/替换到EC2实例的方法。 cloudhackers上的文档提供了一种使用IAM角色运行图像但不附加的方法。

用boto可以吗?否则,我需要手动操作。

答案

阅读文档here

associate_iam_instance_profile(** kwargs) 将IAM实例配置文件与正在运行或已停止的实例关联。您不能将多个IAM实例配置文件与实例关联。

请求语法

response = client.associate_iam_instance_profile(
    IamInstanceProfile={
        'Arn': 'string',
        'Name': 'string'
    },
    InstanceId='string'
)

响应语法

{
    'IamInstanceProfileAssociation': {
        'AssociationId': 'string',
        'InstanceId': 'string',
        'IamInstanceProfile': {
            'Arn': 'string',
            'Id': 'string'
        },
        'State': 'associating'|'associated'|'disassociating'|'disassociated',
        'Timestamp': datetime(2015, 1, 1)
    }
}

顺便说一句,你给的链接有一个横幅说

注意您正在查看旧版本boto(boto2)的文档。 Boto3,Boto的下一个版本,现在已经稳定并推荐用于一般用途。

以上是关于python boto3将IAM角色附加/替换为ec2的主要内容,如果未能解决你的问题,请参考以下文章