LoginSignup
1
4

More than 1 year has passed since last update.

AWS SSMでFTPソフトを使用して、ローカルマシンからPrivate EC2へファイル転送

Posted at

これは何

AWS SSMでCyberduck(FTPクライアントソフト)を使用して、Private EC2へファイル転送してみました。
FTPソフトはWinSCPとか他のでもいけると思います。(動作検証はしてませんが)

早速やってみた

IAMロールを作成
AmazonSSMManagedInstanceCore ポリシーを含むロールを作成

スクリーンショット 2021-09-10 16.26.37.png

EC2へアタッチする

先ほど作成したロールをEC2にアタッチします。

AWS CLI v2のインストール、configureコマンドで情報入力
今回は、direnvを使用し、環境変数を定義しました。
こんな感じで

export AWS_ACCESS_KEY_ID=""
export AWS_SECRET_ACCESS_KEY=""
export AWS_DEFAULT_REGION=""

Session Manager pluginのインストール
以下より、マシンに合わせて選択し、インストール。
https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html

鍵ファイルのパーミッションを変更

$ chmod 600 CMS秘密鍵

AWS CLIで利用するIAMユーザーを作成

IAMポリシーの作成

以下のポリシーでSSHが可能。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "ssm:StartSession",
                "ssm:TerminateSession",
                "ssm:ResumeSession",
                "ssm:DescribeSessions",
                "ssm:GetConnectionStatus"
            ],
            "Effect": "Allow",
            "Resource": [
                "*"
            ]
        }
    ]
}

IAMユーザーの作成
上記のポリシーを付与したIAMユーザーを作成。

プログラムによるアクセスを許可。
生成されたアクセスキーとシークレットアクセスキーを先ほどの環境変数に定義する。

ポートフォワーディングをする

$ aws ssm start-session --target 【インスタンスID】 --document-name AWS-StartPortForwardingSession --parameters "portNumber=22,localPortNumber=10220(任意)"

すると、以下の文字を吐きます。

Starting session with SessionId:xxxxx
Port 10220 opened for sessionId xxxxx
Waiting for connections...

Cyberduckでファイル転送

サーバー名 : localhost
ポート名 : 10220
ユーザー名 : OSユーザー名
SSH Private Key : 秘密鍵のFull Path

ターミナルがこんな文字列を吐くようになったら、接続成功です。

Connection accepted for session xxxxx

参考

https://hikari-blog.com/ec2-session-manager/
https://blog.denet.co.jp/ssm-winscp-upl/
https://qiita.com/hayao_k/items/78b5bfe030ad8a053e93

参考にさせていただきました。ありがとうございます。

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