我已经阅读了这个问题How do I use Boto3 to launch an EC2 instance with an IAM role?,并尝试在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.
之后遇到了这个错误,我发现这个问题how do I launch ec2-instance with iam-role?为Ruby
提供了解决问题的方法。有谁能告诉我在python Boto3
中是否有解决这个问题的方法?在
您没有足够的权限(
iam::PassRole
)将IAM角色附加到实例。所以附加一个政策,授予你特权。只有当您是IAM管理员或有足够的权限将策略附加到用户时,才能将策略附加到用户。在PassRole
的策略文档create_policy。请参见:How to give ec2 instance access to s3 using boto3我去查一下- 1如果您对AWS的身份验证是否正确-您可以在客户机中显式指定访问和密钥。在
ec2:runInstances
IAM权限。在相关问题 更多 >
编程相关推荐