2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ECS Execを使ってコンテナにアクセスする手順

2
Posted at

前準備

1. session-manager-puginのインストール

(オプション) AWS CLI 用の Session Manager プラグインをインストールする

2. タスクのIAMロールにSSMエージェント実行用ポリシーをアタッチ

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ssmmessages:CreateControlChannel",
                "ssmmessages:CreateDataChannel",
                "ssmmessages:OpenControlChannel",
                "ssmmessages:OpenDataChannel"
            ],
            "Resource": "*"
        }
    ]
}

3. 下記コマンドを実行

aws ecs update-service --region ap-northeast-1 --cluster ${ECS_CLUSTER_NAME} --service ${SERVICE_NAME} --enable-execute-command

4. タスクを再起動する(現在起動中のタスクにはecs execできない)

aws ecs update-service --force-new-deployment --cluster ${ECS_CLUSTER_NAME} --service ${SERVICE_NAME}

注意点

  • aws ecs update-service後、タスク再起動の必要あり。古いタスクはecs execできない
  • リードオンリーなコンテナにはそもそもアクセスできない

いざコンテナにアクセス

aws ecs execute-command --cluster ${ECS_CLUSTER_NAME} --task ${TASK_ID} --interactive --command "bin/sh"

うまくいかないとき

amazon-ecs-exec-checkerを使って原因調査する。うだうだ原因調査するよりこれが一番早い。

git clone https://github.com/aws-containers/amazon-ecs-exec-checker.git
cd amazon-ecs-exec-checker
./check-ecs-exec.sh <YOUR_ECS_CLUSTER_NAME> <YOUR_ECS_TASK_ID>

使用条件:

  • jqがインストール済みであること
  • aws cliがインストール済みであること
2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?