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

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

我正在尝试使用 boto3 将实例配置文件附加到 EC2 实例。我正在关注 boto3 文档 https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.associate_iam_instance_profile

但失败并出现以下错误:

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

你能帮我解决这个问题吗?

这是代码片段

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

非常感谢您的帮助。

boto3==1.4.3

Python 3.8.6

谢谢

您指的是 boto3 版本 1.17.112 的文档,并且您使用的是有点过时的 boto 版本。因此,如果没有版本限制,您可以做的第一件事就是更新您的 boto3 版本。

pip install boto3==1.17.112