AWS session managerのクライアント設定

AWS

概要

  • AWS Session Managerを使うと踏み台サーバが不要になるのでサーバサイドは設定しました。
  • クライアント側でわざわざEC2のinstance IDを指定するのが大変なのでかんたんにssh接続できるように設定します。

設定手順

同じ作者のshell scriptである、ssh-over-ssmssm-toolを使います。接続のたびに、裏で勝手にsshのキーペアを作成してログインできるようにしてくれます。また、EC2のisntance idを人間がわかりやすい名前でアクセスできるように設定してくれます。

% ghq get [email protected]:elpy1/ssh-over-ssm.git
% cp ~/ghq/github.com/elpy1/ssh-over-ssm/ssh-ssm.sh ~/bin/
% ghq get [email protected]:elpy1/ssm-tool.git
% cp ~/ghq/github.com/elpy1/ssm-tool/ssm-tool ~/bin/
% pip3 install --user -r ~/ghq/github.com/elpy1/ssm-tool/requirements.txt

~/bin/にはpathを通しておきます。

~/.aws/configと~/aws/credentials にIAMのcredentialを設定しておきます。

aws cliをインストールしておきます。それに追加して、session manager pluginをインストールします。

Ubuntuの場合は以下。

% curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb" -o "session-manager-plugin.deb"
% sudo dpkg -i session-manager-plugin.deb

instance idとの関連付け定義ファイルを生成します。

% ssm-tool --ssh-conf

以下のような設定ファイルが生成されます。

あとは、わかり易い名前を指定するだけでsshでは入れます。

ホストの一覧ファイルを作るのにひと手間かかりますが、fishであればホスト名の補完ができるようになるので楽です。

まとめ

  • session managerを使ってかんたんにログインできるようにするツールを導入しました。

コメント

  1. matsubokkuri より:

    `An error occurred (TargetNotConnected) when calling the StartSession operation: i-xxxxxxx` っていうエラーが一部のホストへ接続するときに出ましたが、接続しようとしているホストのインスタンスを再起動したら接続できるようになりました(謎)