Amazon ECS Execで コンテナに接続する方法
ECS Execの登場でコンテナアプリケーションでもデバッグが容易に!
Amazon ECS、Fargateを使用している際、デバッグに苦労した経験はないでしょうか。
かつてはAWS Sesstion Manager で Fargate に SSH 接続したりと工夫が必要でしたが、ECS Execの登場でコンテナへの接続が容易になりました。
以下、接続方法を簡単に紹介します。
タスク IAM ロールに以下のポリシーを適用
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ssmmessages:CreateControlChannel", "ssmmessages:CreateDataChannel", "ssmmessages:OpenControlChannel", "ssmmessages:OpenDataChannel" ], "Resource": "*" } ] }
サービスに対しECS Execの有効化
aws ecs update-service \ --cluster cluster-name \ --service service-name \ --enable-execute-command
enableExecuteCommand プロパティがtrueになっているか確認
aws ecs describe-tasks \ --cluster cluster-name \ --tasks task-id
- "enableExecuteCommand": true になっていることを確認
ECS Exec を使用してコンテナに接続
aws ecs execute-command --cluster cluster-name \ --task task-id \ --container container-name \ --interactive \ --command "/bin/sh"
簡単ですね! ECS Exec ありがたい……。