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

jak*_*aks 2 python amazon-ec2 amazon-web-services boto3

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

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

rae*_*man 7

阅读这里的文档

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

请求语法

response = client.associate_iam_instance_profile(
    IamInstanceProfile={
        'Arn': 'string',
        'Name': 'string'
    },
    InstanceId='string'
)
Run Code Online (Sandbox Code Playgroud)

响应语法

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

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

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