aws / session-manager-plugin

This plugin helps you to use the AWS Command Line Interface (AWS CLI) to start and end sessions to your managed instances
Apache License 2.0
257 stars 69 forks source link

An error occurred (TargetNotConnected) when calling the ...is not connected. #72

Open dev-samples opened 1 year ago

dev-samples commented 1 year ago

Based on: https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html

In am trying to connect to a container running in a Fargate task using the session manager from my local machine (Mac M1).

I have installed:

curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/mac_arm64/session-manager-plugin.pkg" -o "session-manager-plugin.pkg"
sudo installer -pkg session-manager-plugin.pkg -target /
sudo ln -s /usr/local/sessionmanagerplugin/bin/session-manager-plugin /usr/local/bin/session-manager-plugin

And based on: https://stackoverflow.com/a/67641633/363603

I am trying to start it with:

# ecs:<cluster-name>_<task-id>_<container-runtime_id>
aws ssm start-session --target ecs:sample-cluster_efe***9e0_efe***536

but get:

An error occurred (TargetNotConnected) when calling the StartSession operation: ecs:sample-cluster_ef***a9e0_efe**536 is not connected.

I also tried to add:

        {
            "Effect": "Allow",
            "Action": [
                "ssmmessages:CreateControlChannel",
                "ssmmessages:CreateDataChannel",
                "ssmmessages:OpenControlChannel",
                "ssmmessages:OpenDataChannel"
            ],
            "Resource": "*"
        }

to the Fargate task IAM role but besides from that I have not done anything special to on my Fargate task so most likely I am missing some config from: https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-prerequisites.html

but any input is appreciated!

kenkoooo commented 1 month ago

I'm not sure if you're still encountering this issue, but I resolved a similar problem by adding "enableExecuteCommand": true to the service definition.