【问题标题】:`aws ecs execute-command` results in `TargetNotConnectedException` `The execute command failed due to an internal error``aws ecs execute-command` 导致 `TargetNotConnectedException` `由于内部错误,执行命令失败`
【发布时间】:2021-09-21 14:20:45
【问题描述】:

我正在一个 ECS 集群上运行一个 Docker 镜像,以便在其中运行一些简单的测试。但是,当我运行它时:

aws ecs execute-command  \
  --cluster MyEcsCluster \
  --task $ECS_TASK_ARN \
  --container MainContainer \
  --command "/bin/bash" \
  --interactive

我得到错误:

The Session Manager plugin was installed successfully. Use the AWS CLI to start a session.


An error occurred (TargetNotConnectedException) when calling the ExecuteCommand operation: The execute command failed due to an internal error. Try again later.

我可以确认任务+容器+代理都在运行:

aws ecs describe-tasks \
  --cluster MyEcsCluster \
  --tasks $ECS_TASK_ARN \
  | jq '.'
      "containers": [
        {
          "containerArn": "<redacted>",
          "taskArn": "<redacted>",
          "name": "MainContainer",
          "image": "confluentinc/cp-kafkacat",
          "runtimeId": "<redacted>",
          "lastStatus": "RUNNING",
          "networkBindings": [],
          "networkInterfaces": [
            {
              "attachmentId": "<redacted>",
              "privateIpv4Address": "<redacted>"
            }
          ],
          "healthStatus": "UNKNOWN",
          "managedAgents": [
            {
              "lastStartedAt": "2021-09-20T16:26:44.540000-05:00",
              "name": "ExecuteCommandAgent",
              "lastStatus": "RUNNING"
            }
          ],
          "cpu": "0",
          "memory": "4096"
        }
      ],

我正在使用 CDK Typescript 代码定义 ECS 集群和任务定义:

    new Cluster(stack, `MyEcsCluster`, {
        vpc,
        clusterName: `MyEcsCluster`,
    })

    const taskDefinition = new FargateTaskDefinition(stack, TestTaskDefinition`, {
        family: `TestTaskDefinition`,
        cpu: 512,
        memoryLimitMiB: 4096,
    })
    taskDefinition.addContainer("MainContainer", {
        image: ContainerImage.fromRegistry("confluentinc/cp-kafkacat"),
        command: ["tail", "-F", "/dev/null"],
        memoryLimitMiB: 4096,
        // Some internet searches suggested setting this flag. This didn't seem to help.
        readonlyRootFilesystem: false,
    })

【问题讨论】:

    标签: amazon-web-services docker amazon-ecs aws-fargate


    【解决方案1】:

    This utility 应该能够找出您的设置有什么问题。可以试试吗?

    【讨论】:

    • 这个工具太棒了。我错过了 ssmmessages IAM 权限;添加这些后,一切正常!非常感谢!
    • 这个实用程序显示一切都被允许,但它仍然给我“执行命令失败,因为在任务运行时未启用执行命令或执行命令代理未运行。”还有其他想法吗?
    • @Uzair 您在使用 EC2 吗?而不是法门?我认为您需要将您的 AMI 更新到最新版本。我没有链接,但我读到旧版本的 AMI 不支持它。总帐
    • 该工具显示 Exec Enabled for Task: No,但其他一切都是绿色的。我看不到如何为任务启用 exec。它在 Fargate 上运行,所以它应该已经默认启用,不是吗?我完成了创建新服务的动作,但没有复选框或类似的启用 exec
    • 好的,所以你只能通过命令行来做:aws ecs update-service --cluster your-cluster-name --enable-execute-command --service your-service-name
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-23
    • 2018-11-06
    • 2015-12-18
    • 2015-12-16
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多