[英]Unauthorized operation error occurs when using Boto3 to launch an EC2 instance with an IAM role
我已经阅读了这个问题, 如何使用Boto3启动具有IAM角色的EC2实例? 并尝试在python脚本中启动具有IAM角色的实例。 这是代码:
instance = ec2.create_instances(
ImageId='ami-1a7f6d7e',
KeyName='MyKeyPair',
MinCount=1,
MaxCount=1,
SecurityGroups=['launch-wizard-3'],
InstanceType='t2.micro',
IamInstanceProfile={
'Arn': 'arn:aws:iam::627714603946:instance-profile/SSMforCC'}
)
但是,在运行脚本botocore.exceptions.ClientError: An error occurred (UnauthorizedOperation) when calling the RunInstances operation: You are not authorized to perform this operation.
后,我收到此错误botocore.exceptions.ClientError: An error occurred (UnauthorizedOperation) when calling the RunInstances operation: You are not authorized to perform this operation.
我发现了这个问题, 如何使用iam-role启动ec2-instance? 为Ruby
提供解决方案。 有人可以告诉我python Boto3
是否有办法解决这个问题吗?
您没有足够的特权( iam::PassRole
)将IAM角色附加到实例。 因此,请附上授予您特权的策略。 仅当您是IAM管理员或具有足够的特权将策略附加到用户时,才可以将策略附加到用户。
PassRole
的策略文档创建create_policy 。 请参阅: 如何使用boto3使ec2实例访问s3 我会检查-1.如果您正确或不正确地向AWS进行身份验证-您可以在客户端中显式指定访问和密钥。
client = boto3.client(
'ec2',
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
)
ec2:runInstances
IAM权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.