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)
    }
}

顺便说一句,您给的链接顶部有一个横幅

Note You are viewing the documentation for an older version of boto
(boto2). Boto3, the next version of Boto, is now stable and
recommended for general use.

上一篇:AWS Secrets Manager


下一篇:我如何使用AWS Lambda通过创建临时文件将“文件”上传到S3?