在 EC2 实例启动期间收到 "UnauthorizedOperation" 错误消息后,如何解码授权失败消息?
我在尝试启动 Amazon Elastic Compute Cloud (Amazon EC2) 实例时收到错误讯息:"An error occurred (UnauthorizedOperation) when calling the RunInstances operation: You are not authorized to perform this operation.Encoded authorization failure message encoded-message"。如何解决此问题?
简短描述
"UnauthorizedOperation" 错误表示附加到 AWS Identity and Access Management (IAM) 角色的权限,或尝试执行操作的用户不具有所需的权限来启动 EC2 实例。由于此错误涉及一个编码消息,因此,请使用 AWS Command Line Interface (AWS CLI) 来解码此消息。此解码可提供有关授权失败的更多详细信息。
先决条件
试图解码已编码消息的 IAM 用户或角色必须具有使用 IAM 策略执行 DecodeAuthorizationMesssage API 操作的权限。如果用户或角色没有此权限,则解码操作会失败,并显示以下错误消息:
"Error: A client error (AccessDenied) occurred when calling the DecodeAuthorizationMessage operation: User: xxx is not authorized to perform: (sts:DecodeAuthorizationMessage) action"。
解决方法
1. 通过以下命令,验证您的计算机上已安装并配置了 AWS CLI:
$ aws --version
**注意:**如果在运行 AWS CLI 命令时遇到错误,请确保您使用的是最新版本的 AWS CLI。
2. 运行 decode-authorization-message 命令。将 encoded-message 替换为错误消息中包含的编码消息。
$ aws sts decode-authorization-message --encoded-message encoded-message
3. 已解码消息会列出 IAM 角色或用户策略中缺少的所需权限。
编码的消息示例:
Launch Failed - You are not authorized to perform this operation. Encoded authorization failure message: 4GIOHlTkIaWHQD0Q0m6XSnuUMCm-abcdefghijklmn-abcdefghijklmn-abcdefghijklmn
解码后的消息示例:
$ aws sts decode-authorization-message --encoded-message 4GIOHlTkIaWHQD0Q0m6XSnuUMCm-abcdefghijklmn-abcdefghijklmn-abcdefghijklmn { "DecodedMessage": "{\"allowed\":false,\"explicitDeny\":false,\"matchedStatements\":{\"items\":[]},\"failures\":{\"items\":[]},\"context\":{\"principal\":{\"id\":\"ABCDEFGHIJKLMNO\",\"name\":\"AWS-User\", \"arn\":\"arn:aws:iam::accountID:user/test-user\"},\"action\":\"iam:PassRole\", \"resource\":\"arn:aws:iam::accountID:role/EC2_instance_Profile_role\",\"conditions\":{\"items\":[{\"key\":\"aws:Region\",\"values\":{\"items\":[{\"value\":\"us-east-2\"}]}}, {\"key\":\"aws:Service\",\"values\":{\"items\":[{\"value\":\"ec2\"}]}},{\"key\":\"aws:Resource\",\"values\":{\"items\":[{\"value\":\"role/EC2_instance_Profile_role\"}]}}, {\"key\":\"iam:RoleName\",\"values\":{\"items\":[{\"value\":\"EC2_instance_Profile_role\"}]}},{\"key\":\"aws:Account\",\"values\":{\"items\":[{\"value\":\"accountID\"}]}}, {\"key\":\"aws:Type\",\"values\":{\"items\":[{\"value\":\"role\"}]}},{\"key\":\"aws:ARN\",\"values\":{\"items\":[{\"value\":\"arn:aws:iam::accountID:role/EC2_instance_Profile_role\"}]}}]}}}" }
上述错误消息表示调用 RunInstances 请求失败,是因为 AWS-User 没有在 arn:aws:iam::accountID:role/EC2_instance_Profile_role 上执行 iam:PassRole 操作的权限。
4. 编辑与 IAM 角色或用户关联的 IAM 策略,以添加上一步中列出的缺少的所需权限。
相关信息
相关内容
- AWS 官方已更新 1 年前
- AWS 官方已更新 1 年前
- AWS 官方已更新 3 年前