iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐈

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:
https://dev.classmethod.jp/articles/ecs-exec/

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.ssmmessages is required.
      • The enableExecuteCommand property of the running ECS task must be set to true.
    • Connecting Machine Setup (e.g., local macOS):

Must-read: Official Steps

https://docs.aws.amazon.com/AmazonECS/latest/userguide/ecs-exec.html#ecs-exec-prerequisites

Conclusion

If you have prepared the above but still cannot connect, use the Amazon ECS Exec Checker also provided officially.

https://github.com/aws-containers/amazon-ecs-exec-checker

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.
GitHubで編集を提案

Discussion