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.
Is it possible with boto? Otherwise, I need to do it manual.
Read the docs here
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.
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). Boto3, the next version of Boto, is now stable and recommended for general use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With