AWS fargate ecs ssm:无法在 fargate ecs 容器上启动到远程主机的端口转发会话,但可以在实例上执行此操作

问题描述 投票:0回答:1

我无法在 Fargate ecs 容器上启动到远程主机的端口转发会话(或只是远程会话),但可以在实例上执行此操作。使用AWS控制台(这是基于网站的,而不是基于shell的)我似乎无法弄清楚需要什么设置。

工作(实例远程会话):

aws ssm start-session \
--target i-{instance} \
--region {region} \
--profile {profile} \
--document-name AWS-StartPortForwardingSessionToRemoteHost \
--parameters '{"portNumber":["22"],"localPortNumber":["9999"],"host":["{host}"]}'

在集装箱上的工作效果不一样:

aws ssm start-session \
--target ecs:{clusterName}_{taskId}_{containerRuntimeId} \
--region {region} \
--profile {profile} \
--document-name AWS-StartPortForwardingSessionToRemoteHost \
--parameters '{"portNumber":["22"],"localPortNumber":["9999"],"host":["{host}"]}'

有什么想法吗?我得到的只是:

An error occurred (TargetNotConnected) when calling the StartSession operation bla bla

我什至创建了一个 iam policy 并附加到在 ecs 集群内运行特定服务和任务的 iam roles

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ssm:StartSession",
                "ecs:ExecuteCommand"
            ],
            
            "Resource": [
                "arn:aws:ecs:blablabla:cluster/{clusterName}",
                "arn:aws:ssm:blablabla::document/AWS-StartInteractiveCommand",
                "arn:aws:ssm:blablabla::document/AWS-StartPortForwardingSession",
                "arn:aws:ssm:blablabla::document/AWS-StartPortForwardingSessionToRemoteHost"
            ]
        }
    ]
}
amazon-web-services amazon-ecs aws-fargate aws-ssm
1个回答
0
投票

因为是 ECS Fargate,所以你最好使用 Amazon ECS Exec

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html

aws ecs execute-command \
    --cluster ${YOUR_CLUSTER_NAME} \
    --task ${YOUR_TASK_ID} \
    --container ${YOUR_CONTAINER_NAME} \
    --interactive \
    --command "/bin/sh"

有一些注意事项和先决条件,请仔细阅读并确保安装了Session Manager插件

© www.soinside.com 2019 - 2024. All rights reserved.