📝
ECSデバッグ方法
ecsのデバッグ方法としてecs exec を使う方法が有名なので紹介します。
手順
- Session Manager プラグインインストール
https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html#install-plugin-macos
curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/mac/sessionmanager-bundle.zip" -o "sessionmanager-bundle.zip"
unzip sessionmanager-bundle.zip
sudo ./sessionmanager-bundle/install -i /usr/local/sessionmanagerplugin -b /usr/local/bin/session-manager-plugin
インストールされたかの確認
session-manager-plugin
下記のように表示されればOK
The Session Manager plugin was installed successfully. Use the AWS CLI to start a session.
- 権限追加
ecsTaskExecutionRoleに下記のインラインポリシーをアタッチする
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ssmmessages:CreateControlChannel",
"ssmmessages:CreateDataChannel",
"ssmmessages:OpenControlChannel",
"ssmmessages:OpenDataChannel"
],
"Resource": "*"
}
]
}
- サービスの設定を更新する
aws ecs update-service \
--region ap-northeast-1 \
--cluster クラスター名 \
--service サービス名 \
--enable-execute-command
- サービスを起動し直す
コンソール画面から強制デプロイで行い
サービスの更新を行う
- コンテナに入る
aws ecs execute-command \
--region ap-northeast-1 \
--cluster クラスター名 \
--task タスクID \
--container コンテナ名 \
--interactive \
--command "/bin/sh"
Discussion