简体   繁体   中英

AttributeError: 'EC2' object has no attribute 'associate_iam_instance_profile'

I am trying to attach instance profile to an EC2 instance using boto3. I am following boto3 documentation https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.associate_iam_instance_profile

But It fails with below error:

AttributeError: 'EC2' object has no attribute 'associate_iam_instance_profile'

Could you please help me with this ?

This is the code snippet

import boto3

ec2=boto3.client('ec2',region_name='ca-central-1')

response = ec2.associate_iam_instance_profile(IamInstanceProfile={'Arn': 'arn:aws:iam::1234567890:instance-profile/instanceprofilename','Name': 'instanceprofilename'},InstanceId='i-1234567890')

A help will be much appreciated.

boto3==1.4.3

Python 3.8.6

Thanks

You are referring to documentation of boto3 version 1.17.112 and you are using a bit outdated boto version. So if there is no version constraint first thing you can do is to update your boto3 version.

pip install boto3==1.17.112

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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