跳至內容

如何解決 Amazon ECS 中的 "An error occurred (TargetNotConnectedException) when calling the ExecuteCommand operation" 錯誤?

2 分的閱讀內容
0

我嘗試在 Amazon Elastic Container Service (Amazon ECS) 中執行 execute-command AWS 命令​​列介面 (AWS CLI) 命令。但我收到了 "An error occurred (TargetNotConnectedException) when calling the ExecuteCommand operation: The execute command failed due to an internal error. Try again later" 錯誤訊息。

簡短描述

您會因為以下原因收到 "ExecuteCommand" 錯誤訊息:

解決方法

**注意:**如果您在執行 AWS CLI 命令時收到錯誤,請參閱對 AWS CLI 錯誤進行疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本

更新 Amazon ECS 任務角色權限

請完成下列步驟:

  1. 建立下列 IAM 政策
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "ssmmessages:CreateControlChannel",
            "ssmmessages:CreateDataChannel",
            "ssmmessages:OpenControlChannel",
            "ssmmessages:OpenDataChannel"
          ],
          "Resource": "*"
        }
      ]
    }
    **注意:**確保您的組態不會在 AWS Organizations 層級封鎖上述權限。
  2. 將政策附加到 Amazon ECS 任務角色

更新任務角色權限時可能會出現延遲。將政策附加到任務角色後等待幾分鐘,然後執行 execute-command 命令。

檢查 IAM 使用者或角色權限

若要檢查您登入的 IAM 使用者 ID 和角色,請執行以下命令:

 aws sts get-caller-identity

執行 execute-command 命令的 IAM 使用者或角色必須具有下列權限:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "ecs:ExecuteCommand",
      "Resource": "arn:aws:ecs:example-region:example-arn:cluster/example-cluster/*"
    }
  ]
}

為使用者或角色附加新政策更新現有政策,以包含上述權限。

檢查任務定義中是否將 pidMode 設定為 task

每個程序 ID (PID) 命名空間只能有一個 ECS Exec 工作階段。如果您在任務中共用 PID 命名空間,則只能在一個容器中啟動 ECS Exec 工作階段。

檢查您是否在任務定義中將 readonlyRootFilesystem 設為 true

若要建立所需的目錄和檔案,SSM 代理程式需要一個可寫入的容器檔案系統。您不能使用 readonlyRootFilesystem 任務定義參數或任何其他方法,將根檔案系統變成唯讀。

如果更新任務定義後仍出現錯誤,請從 GitHub 網站執行 amazon-ecs-exec-checkeramazon-ecs-exec-checker 指令碼可驗證您的 AWS CLI 環境以及 Amazon ECS 叢集或任務。如果您不符合先決條件,該指令碼也會通知您。

相關資訊

使用 ECS Exec

AWS 官方已更新 6 個月前