iTranslated by AI
Troubleshooting ECS Exec Connection Issues for Fargate Tasks
AWS Fargate is a very convenient managed service since you don't have to manage the OS.
Many of you are likely running production applications on Fargate.
In this article, I will introduce the steps to handle cases where you cannot connect via ECS Exec, as the official documentation provides thorough support.
Official Reference:
Note: I am simply following the official steps, and this is a topic that has been covered many times before.
Prerequisites
- You meet the conditions listed in the official prerequisites.
- Tasks and AWS Environment Setup:
- Grant necessary IAM permissions to the Task Role (Note: This is not the Task Execution Role).
- For Fargate, ensure you are using Platform Version 1.4.0 or higher.
- For private subnets, ensure the necessary VPC endpoints are implemented.
-
com.amazonaws.ap-northeast-1.ssmmessagesis required.
-
- The
enableExecuteCommandproperty of the running ECS task must be set totrue.
- Connecting Machine Setup (e.g., local macOS):
- Install the Session Manager plugin for the AWS CLI.
- https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html
- Tasks and AWS Environment Setup:
Must-read: Official Steps
Conclusion
If you have prepared the above but still cannot connect, use the Amazon ECS Exec Checker also provided officially.
Make sure to have jq and aws cli (refer to the README in the repository above for version requirements) ready beforehand.
Simply clone the repository and run the shell script; it will tell you what is missing.
./check-ecs-exec.sh <cluster-name> <task-id>
In my case, it pointed out that the VPC endpoint was missing, as shown below:
-------------------------------------------------------------
Prerequisites for check-ecs-exec.sh v0.7
-------------------------------------------------------------
jq | OK (/opt/homebrew/bin/jq)
AWS CLI | OK (/usr/local/bin/aws)
-------------------------------------------------------------
Prerequisites for the AWS CLI to use ECS Exec
-------------------------------------------------------------
AWS CLI Version | OK (aws-cli/2.1.32 Python/3.8.8 Darwin/20.6.0 exe/x86_64 prompt/off)
Session Manager Plugin | OK (1.2.295.0)
...(omitted)
SSM PrivateLink "com.amazonaws.ap-northeast-1.ssmmessages" not found. You must ensure your task has proper outbound internet connectivity.
Discussion