0
1

ECS FargateにSSMを利用してSSH接続するのに参考にした記事メモ

Last updated at Posted at 2024-07-16

完全に自分のメモとして、参考にした記事とハマったところを残します。

ECSExecの有効化

まずはこの記事を参考に、AWS-CLIにSSMのプラグインをインストールし、ECSExecの有効化を実行するのですが、

An error occurred (InvalidParameterException) when calling the UpdateService operation: The service couldn't be updated because a valid taskRoleArn is not being used. Specify a valid task role in your task definition and try again.

上記のようなエラーが出て、タスク定義のタスクロールが必要とのこと。

https://dev.classmethod.jp/articles/tsnote-ecs-update-service-fails-with-invalidparameterexception-in-ecs-exec/
ここにあるようなPolicyを付与したロールをタスクロールに設定。

この後、

$ aws ecs update-service --region ap-northeast-1 --cluster クラスター名 --service サービス名 --enable-execute-command

を実行して、有効化に成功。

SSH接続の実行

aws ecs execute-command --region ap-northeast-1 --cluster クラスター名 --task タスクID --container コンテナ名 --interactive --command "/bin/sh"

を実行してみたが、以下エラーに。

The Session Manager plugin was installed successfully. Use the AWS CLI to start a session.

An error occurred (InvalidParameterException) when calling the ExecuteCommand operation: The execute command failed because execute command was not enabled when the task was run or the execute command agent isn’t running. Wait and try again or run a new task with execute command enabled and try again.

'Wait and try again or run a new task with execute command enabled and try again.'
とあるので、タスクを再実行してから、もう一度SSH接続のコマンドを実行すると、

Starting session with SessionId: ecs-execute-command-l35usyzum4ftb2rc6ezwc2nmke
#

となり、成功!!

0
1
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
0
1