python boto3将IAM角色附加/替换为ec2 [英] python boto3 attach/replace IAM role to ec2

查看:147
本文介绍了python boto3将IAM角色附加/替换为ec2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到通过boto3将IAM角色附加/替换到EC2实例的方法。

cloudhackers 提供了一种方法来运行具有IAM角色但不附加的映像。

I could not find a way to attach/replace an IAM role to the EC2 instance via boto3.
The documentation at cloudhackers provides a method to run image with IAM role, but not to attach.

boto是否有可能?否则,我需要手动完成。

Is it possible with boto? Otherwise, I need to do it manual.

推荐答案

阅读文档此处

associate_iam_instance_profile (** kwargs)

将IAM实例配置文件与正在运行或已停止的实例相关联。您不能将一个以上的IAM实例配置文件与一个实例相关联。

associate_iam_instance_profile(**kwargs)
Associates an IAM instance profile with a running or stopped instance. You cannot associate more than one IAM instance profile with an instance.

请求语法

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

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

By the way, the link you gave has a banner on top saying


注意您正在查看旧版本的boto
的文档( boto2)。 Boto3的下一个版本Boto3现在已经稳定,建议使用

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.

这篇关于python boto3将IAM角色附加/替换为ec2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆