AWS Builder Center: Learn, Build and Connect with builders in the AWS community
AWS Builder Center is the official home for builders on AWS. Share and read what others are working on, follow people who inspire you, explore training and workshops, and find tools to support what you're building.
如何解碼和分析 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". (在呼叫 RunInstances 操作時發生錯誤 (UnauthorizedOperation):您並沒有執行此操作的授權。編碼授權錯誤訊息 encoded-message)
簡短說明
當 AWS Identity and Access Management (IAM) 政策限制過多時,可能會發生 UnauthorizedOperation 錯誤。當 IAM 使用者沒有啟動 EC2 執行個體的權限時,也可能會發生此錯誤。若要取得失敗的詳細資訊,請使用 AWS Command Line Interface (AWS CLI) 或 AWS CloudShell 解碼錯誤訊息中的編碼訊息。編碼的訊息看起來類似於下列範例:
「啟動失敗 - 您沒有執行此作業的權限。編碼授權失敗訊息: 4GIOHlTkIaWHQD0Q0m6XSnuUMCm-abcdefghijklmn-abcdefghijklmn-abcdefghijklmn」
**注意:**若要解碼編碼訊息,IAM 使用者或角色必須具有執行 DecodeAuthorizationMesssage API 作業的權限。如果使用者或角色沒有該權限,則解碼作業會失敗並顯示下列錯誤訊息:
「錯誤: 呼叫 DecodeAuthorizationMessage 作業時發生用戶端錯誤 (AccessDenied): 使用者:### 無權執行:(sts:DecodeAuthorizationMessage) 動作」。
解決方法
**注意:**如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤訊息,請參閱對 AWS CLI 錯誤進行疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本。
若要解碼授權失敗錯誤,請完成下列步驟:
- 執行 decode-authorization-message 命令:
**注意:**將 encoded-message-error 替換為錯誤訊息中的編碼訊息。aws sts decode-authorization-message --encoded-message encoded-message-error
解碼訊息範例:
解碼訊息會列出 IAM 使用者或角色政策中缺少的必要權限。aws sts decode-authorization-message --encoded-message 4GIOHlTkIaWHQD0Q0m6XSnuUMCm-abcdefghijklmn-abcdefghijklmn-abcdefghijklmn{ "DecodedMessage": { "allowed ... "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\"}]}}]}}}" } - 查看解碼訊息中的主體、動作、資源、條件和索引鍵欄位,以取得有關失敗原因的更多資訊。此訊息包含請求的動作和資源、提出請求的主體,以及使用者請求的條件索引鍵值。
在上述範例中,因為 AWS-User 沒有在 arn:aws:iam::accountID:role/EC2_instance_Profile_role ARN 上執行 iam:PassRole 動作的權限,導致請求失敗。 - 編輯與 IAM 使用者或角色關聯的 IAM 政策,以新增必要權限。
您也可以使用 IAM 政策模擬器來疑難排解身分型政策和 IAM 權限界限。
相關資訊
相關內容
已提問 3 年前
已提問 3 年前
已提問 2 年前
