LoginSignup
20
3

More than 1 year has passed since last update.

ECS Execでトラブルが起きたら、amazon-ecs-exec-checkerを使ってみよう

Last updated at Posted at 2022-07-05

ECS Execは、ECSで稼働しているコンテナに対しコマンドを実行できる仕組みです。

ローカル環境だと出ないエラーが出てしまって、原因がわからない場合や、
VPC内のリソース以外からはRDSへの接続が許可されていない場合に活躍します。
仰々しい名前が付いていますが、独立したサービスではなく、SSMでコンテナに接続する感じです。
AWS CLIが入っていれば、ぜひ試してみてください。

導入方法は下記のドキュメントを御覧ください。
https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/userguide/ecs-exec.html

さて、ECS Execするための設定なのですが、
簡単そうに見えて、ネットワークなどの設定によっては、一発で繋がらない事もあります。
AWS Execでは色々と隠蔽されているのもあり、トラブルの原因を探るのはなかなか難しい。
(よくあるのは、ssmmessagesへの権限付与が足りないとか..VPC Endpointがないとか..)

そんなときに役立つのが、 amazon-ecs-exec-checker です。

公式のツールです。
ヤバいことに、Git Cloneしなくても実行できます

下記のコマンドでもチェック可能です。

$ export AWS_PROFILE=myprofile # プロファイル使っているなら指定
$ export AWS_REGION=ap-northeast-1 # 適宜リージョンを指定
$ bash <( curl -Ls https://raw.githubusercontent.com/aws-containers/amazon-ecs-exec-checker/main/check-ecs-exec.sh ) <ECSクラスター名> <ECSタスクID>

ECSクラスター名と、タスクIDを引数に渡すと、以下のように理由を教えてくれます。

🔴 Read-Only Root Filesystem | ReadOnly
ECS Exec uses the SSM agent as its managed agent, and the agents requires that the container file system is able to be written in order to create the required directories and files. Therefore, you need to set the readonlyRootFilesystem flag as false in your task definition to exec into the container using ECS Exec. See the "Considerations for using ECS Exec" in the ECS official documentation for more details.

めっちゃ便利ですね!!!

20
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
3