カテゴリー
AWS

AWS CLIでEC2のWindowsにコマンド実行

ssmてのを使うと、aws cliでWindowsにコマンドが打てることがわかった。
EC2のWindowsにはすでにssmエージェントが入っているので、それをAWSのSSMの画面のクイックスタートでインスタンスを認識させる。

操作する側のローカルのPCにはAWS CLIに追加してSession Manager Pluginもインストールが必要。
(オプション) AWS CLI 用の Session Manager Plugin をインストールする
https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html

ipconfigを実行してみる

C:\>aws ssm send-command --instance-ids "i-00a25be4c15f09999" --document-name "AWS-RunPowerShellScript" --parameters commands=ipconfig --query "Command.CommandId" --output text
59cd40d6-d8ec-47ea-aed3-83e0751c9999

コマンドIDが返って来て、それの結果を見てみると

C:\>aws ssm list-command-invocations --command-id "59cd40d6-d8ec-47ea-aed3-83e0751c9999" --details --query "CommandInvocations[*].CommandPlugins[*].Output[]" --output text

Windows IP Configuration


Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : ap-northeast-1.compute.internal
   Link-local IPv6 Address . . . . . : fe80::3826:5177:9d6b:eb91%6
   IPv4 Address. . . . . . . . . . . : 172.31.45.26
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . : 172.31.32.1

EC2上でipconfigを叩いた結果が見れる

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください