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

问题描述 投票:1回答:1

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

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

python amazon-web-services amazon-ec2 boto3
1个回答
5
投票

阅读文档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的下一个版本,现在已经稳定并推荐用于一般用途。

© www.soinside.com 2019 - 2024. All rights reserved.