LoginSignup
0

posted at

updated at

AWS ECSへの(シェル)アクセス方法 (SSH)

注意点

セキュリティの観点から本番環境への適用は行わないほうが良いと思われます。

接続したいECSサービスのタスクロールに以下のポリシーをアタッチ

※ タスク実行ロールではないです。

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

ECSコンテナへのSSHを許容するようECSサービスへ設定

## このタイミングでECSサービスが再起動します。
aws ecs update-service \
    --cluster クラスター名 \
    --service サービス名 \
    --enable-execute-command --force-new-deployment

ECSタスクが再起動後に確認

## enableExecuteCommandがtrueになっていること
aws ecs describe-tasks \
    --cluster クラスター名 \
    --tasks タスクID (fsajfkadfjkasfjla)

ECSタスクのコンテナへのシェルアクセス (sshのイメージ)

aws ecs execute-command \
    --cluster ECSクラスター名 \
    --task ECSタスクID (sakaksjfaksfjkafka) \
    --interactive \
    --container sshしたいコンテナ名 (task defに記載されています) \
    --region ap-northeast-1 \
    --command "/bin/bash"

採用PR

gRPCやマイクロサービス化・二次元コンテンツに興味がある、もしくはチャレンジしてみたいという方は是非一緒に働きましょう!

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
What you can do with signing up
0