简体   繁体   English

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

[英]python boto3 attach/replace IAM role to ec2

I could not find a way to attach/replace an IAM role to the EC2 instance via boto3. 我找不到通过boto3将IAM角色附加/替换到EC2实例的方法。
The documentation at cloudhackers provides a method to run image with IAM role, but not to attach. cloudhackers的文档提供了一种运行具有IAM角色但不附加的映像的方法。

Is it possible with boto? Boto可以吗? Otherwise, I need to do it manual. 否则,我需要手动进行。

Read the docs here 此处阅读文档

associate_iam_instance_profile(**kwargs) associate_iam_instance_profile(** kwargs)
Associates an IAM instance profile with a running or stopped instance. 将IAM实例配置文件与正在运行或已停止的实例相关联。 You cannot associate more than one IAM instance profile with an instance. 您不能将一个以上的IAM实例配置文件与一个实例相关联。

Request Syntax 请求语法

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

Response Syntax 响应语法

{
    '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 顺便说一句,您给的链接顶部有一个横幅

Note You are viewing the documentation for an older version of boto (boto2). 注意您正在查看文档的旧版本的boto(boto2)。 Boto3, the next version of Boto, is now stable and recommended for general use. Boto3的下一个版本Boto3现在稳定并推荐用于一般用途。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM