1
1

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 5 years have passed since last update.

AWS SessionManager のセッションを任意のコマンドで開始する

Posted at

注) 対応する公式のドキュメントを私の方では見つけられなかったため、正しい方法でない可能性があります。

通常、 SessionManager でセッションを開始すると sh コマンドが実行された状態で開始されると思います。
例えば、任意のシェルでログインしたり、 rails console を実行した状態で開始したいなと思ったので、調査を行いました。

SessionManager の設定 (Document) には、 sessionType という項目があります。

公式のドキュメントの例 では、 Standard_Stream というものを使っていますが、 他に InteractiveCommands というものがあるようです。

また、 InteractiveCommands を指定した場合、 properties という項目を追加でき、そこに開始時のコマンドを指定できるようです。

SSM-SessionManagerCustomRunShell
{
  "schemaVersion": "1.0",
  "description": "Document to hold regional settings for Session Manager",
  "sessionType": "InteractiveCommands",
  "inputs": {
    "s3BucketName": "MyBucket",
    "cloudWatchLogGroupName": "MyLogGroup",
    "runAsEnabled": true
  },
  "properties": {
    "linux": {
      "commands": "rails console",
      "runAsElevated": false
    }
  }
}

上記のような Document を AWS CLI もしくはマネジメントコンソールから作成します。

作成した Document を指定し、セッションを開始すると指定したコマンドでセッションを開始することができます。

aws ssm start-session --document-name SSM-SessionManagerCustomRunShell --target i-XXXXXXXXXXXXX

この機能に関するリリースノートはおそらくこちらですが、対応するドキュメントは見つけられませんでした。(2019/09/12)

amazon-ssm-agent のソースコードを眺めていたところ、それっぽいコミットがあったため試してみたら使えてしまったという形になります。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?