Amazon Lightsail の Windows Server をハイブリッドアクティベーションを利用して SSM のマネージドノード登録されるようにやってみた
はじめに
テクニカルサポートの 片方 です。
今回は、Amazon Lightsail の Windows Server 2022 を起動させて SSM のマネージドノード登録されるようにやってみました。なお、SSM のマネージドノードとして登録させるためにハイブリッドアクティベーションを利用します。
やってみた
弊社ブログ、管理アカウントのセクションまでを参考に "Activation Code " と "Activation ID" を取得 ~ メモしてください。
Amazon Lightsail の Windows Server 2022 を起動させて、RDP 接続を行います。
PowerShell を開き以下のコマンドを実行します。
※ 実行コマンド例
取得~メモした "Activation Code " と "Activation ID" を利用して以下を適宜修正してください
- $code = ""
- $id = ""
- $region = ""
# TLS 1.2 を使用するように設定
[System.Net.ServicePointManager]::SecurityProtocol = 'TLS12'
# アクティベーション情報を設定
$code = "bHtxxxxxxxxxxxx"
$id = "caf1xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$region = "ap-northeast-1"
# 一時ディレクトリを作成
$dir = $env:TEMP + "\ssm"
New-Item -ItemType directory -Path $dir -Force
cd $dir
# 最新のセットアップツールをダウンロード
(New-Object System.Net.WebClient).DownloadFile("https://amazon-ssm-$region.s3.$region.amazonaws.com/latest/windows_amd64/ssm-setup-cli.exe", $dir + "\ssm-setup-cli.exe")
# アクティベーションを実行
./ssm-setup-cli.exe -register -activation-code="$code" -activation-id="$id" -region="$region"
# 登録情報とサービスステータスを確認
Get-Content ($env:ProgramData + "\Amazon\SSM\InstanceData\registration")
Get-Service -Name "AmazonSSMAgent"
PowerShellコマンド実行例 ※一部マスクします
PS C:\Users\Administrator> # TLS 1.2 を使用するように設定
>> [System.Net.ServicePointManager]::SecurityProtocol = 'TLS12'
>>
>> # アクティベーション情報を設定
>> $code = "bHtxxxxxxxxxxxx"
>> $id = "caf1xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
>> $region = "ap-northeast-1"
>>
>> # 一時ディレクトリを作成
>> $dir = $env:TEMP + "\ssm"
>> New-Item -ItemType directory -Path $dir -Force
>> cd $dir
>>
>> # 最新のセットアップツールをダウンロード
>> (New-Object System.Net.WebClient).DownloadFile("https://amazon-ssm-$region.s3.$region.amazonaws.com/latest/windows_amd64/ssm-setup-cli.exe", $dir + "\ssm-setup-cli.exe")
>>
>> # アクティベーションを実行
>> ./ssm-setup-cli.exe -register -activation-code="$code" -activation-id="$id" -region="$region"
>>
>> # 登録情報とサービスステータスを確認
>> Get-Content ($env:ProgramData + "\Amazon\SSM\InstanceData\registration")
>> Get-Service -Name "AmazonSSMAgent"
Directory: C:\Users\ADMINI~1\AppData\Local\Temp\2
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 5/4/2025 2:43 AM ssm
2025-05-04 02:44:06 INFO ssm-setup-cli -version: 3.3.2299.0
2025-05-04 02:44:06 INFO Setting proxy config
2025-05-04 02:44:06 DEBUG Current proxy environment variables: https_proxy:;http_proxy:;no_proxy:
2025-05-04 02:44:06 INFO Getting IE proxy configuration for current user: The operation completed successfully.
2025-05-04 02:44:06 DEBUG IE proxy configuration for current user: proxy:,bypass:,enabled:false,automatically detect proxy settings:true,automatic configuration script:
2025-05-04 02:44:06 INFO Getting WinHTTP proxy default configuration: The operation completed successfully.
2025-05-04 02:44:06 DEBUG WinHTTP proxy default configuration: proxy:,bypass:
2025-05-04 02:44:06 DEBUG ParseProxySettings result: http_proxy:<nil>,https_proxy:<nil>
2025-05-04 02:44:06 INFO Proxy environment variables:
2025-05-04 02:44:06 INFO https_proxy:
2025-05-04 02:44:06 INFO http_proxy:
2025-05-04 02:44:06 INFO no_proxy:
2025-05-04 02:44:06 INFO Setup parameters:
2025-05-04 02:44:06 INFO env=
2025-05-04 02:44:06 INFO install=false
2025-05-04 02:44:06 INFO shutdown=false
2025-05-04 02:44:06 INFO role=
2025-05-04 02:44:06 INFO tags=
2025-05-04 02:44:06 INFO register=true
2025-05-04 02:44:06 INFO region=ap-northeast-1
2025-05-04 02:44:06 INFO override=false
2025-05-04 02:44:06 INFO version=
2025-05-04 02:44:06 INFO manifest-url=
2025-05-04 02:44:06 INFO artifactsDir=
2025-05-04 02:44:06 INFO skip-signature-validation=false
2025-05-04 02:44:06 DEBUG Package manager windows is available, checking if agent is installed
2025-05-04 02:44:06 INFO Agent is already installed with windows, selecting it as package manager
2025-05-04 02:44:06 INFO Selecting windows as service manager
2025-05-04 02:44:08 INFO Initialize download manager
2025-05-04 02:44:08 INFO Detected platform Windows
2025-05-04 02:44:08 DEBUG Determining endpoint for service s3 in region ap-northeast-1
2025-05-04 02:44:08 DEBUG [DownloadManager] attempting to download as http/https download from https://s3.ap-northeast-1.amazonaws.com/amazon-ssm-ap-northeast-1/ssm-agent-manifest.json to C:\Users\Administrator\AppData\Local\Temp\2\ssm\ssm_setup_cli_artifacts3248735991\child_3331915685
2025-05-04 02:44:09 INFO [DownloadManager] C:\Users\Administrator\AppData\Local\Temp\2\ssm\ssm_setup_cli_artifacts3248735991\child_3331915685\2b10b61cbf1e65013d883366a1acb297c0bd4b6a with 566148 bytes downloaded
2025-05-04 02:44:10 INFO found package amazon-ssm-agent
2025-05-04 02:44:10 INFO found file amazon-ssm-agent-windows-amd64.zip
2025-05-04 02:44:10 INFO [DownloadManager] Downloading SSM Setup CLI
2025-05-04 02:44:10 DEBUG [DownloadManager] attempting to download as http/https download from https://s3.ap-northeast-1.amazonaws.com/amazon-ssm-ap-northeast-1/latest/windows_amd64/ssm-setup-cli.exe to C:\Users\Administrator\AppData\Local\Temp\2\ssm\ssm_setup_cli_artifacts3248735991\child_3331915685
2025-05-04 02:44:10 INFO [DownloadManager] C:\Users\Administrator\AppData\Local\Temp\2\ssm\ssm_setup_cli_artifacts3248735991\child_3331915685\eba56f799ac4f5c7f6b046dd756cb4b9eb207904 with 10536592 bytes downloaded
2025-05-04 02:44:11 INFO [DownloadManager] Downloaded SSM-Setup-CLI successfully
2025-05-04 02:44:11 INFO Installed agent version - 3.3.1957.0
2025-05-04 02:44:11 INFO Version already installed 3.3.1957.0:
2025-05-04 02:44:11 INFO Attempting to configure agent
2025-05-04 02:44:11 INFO Agent is configured successfully
2025-05-04 02:44:11 INFO Verifying agent is installed before attempting to register
2025-05-04 02:44:11 INFO Verified agent is installed
2025-05-04 02:44:11 INFO Agent is not registered
2025-05-04 02:44:11 INFO Stopping agent before registering
2025-05-04 02:44:11 INFO Stopping agent using windows service manager
2025-05-04 02:44:21 INFO Successfully stopped agent
2025-05-04 02:44:21 INFO Registering agent
2025-05-04 02:44:27 INFO Successfully registered the agent, starting agent
2025-05-04 02:44:27 INFO Starting agent using windows service manager
2025-05-04 02:44:29 INFO Agent is running
2025-05-04 02:44:29 INFO Successfully started agent, reloading registration info
2025-05-04 02:44:29 INFO Successfully registered the instance with AWS SSM using Managed instance-id: mi-006a1230ae8c2c2c9
2025-05-04 02:44:34 INFO Process Path: amazon-ssm-agent.exe
2025-05-04 02:44:34 INFO Agent process count: 1
2025-05-04 02:44:34 INFO Agent registration completed
{"ManagedInstanceID":"mi-006a1230ae8c2c2c9","Region":"ap-northeast-1"}
Status : Running
Name : AmazonSSMAgent
DisplayName : Amazon SSM Agent
PS C:\Users\Administrator\AppData\Local\Temp\2\ssm>
出力結果より、Managed instance-id: mi-006a1230ae8c2c2c9 として登録されました。
それでは、Fleet Manager で該当ノード(Amazon Lightsail の Windows Server 2022)が表示されているか確認します。
成功です!!
まとめ
マネージドノードにすることで、パッチ適用なども簡単になりますね。
本ブログが誰かの参考になれば幸いです。
参考資料
- AWS Systems Manager ハイブリッドアクティベーション - AWS Systems Manager
- AWS Systems Manager ハイブリッドアクティベーションを利用して、他 AWS アカウントの EC2 インスタンスをマネージドノード表示させてみた | DevelopersIO
アノテーション株式会社について
アノテーション株式会社は、クラスメソッド社のグループ企業として「オペレーション・エクセレンス」を担える企業を目指してチャレンジを続けています。「らしく働く、らしく生きる」のスローガンを掲げ、様々な背景をもつ多様なメンバーが自由度の高い働き方を通してお客様へサービスを提供し続けてきました。現在当社では一緒に会社を盛り上げていただけるメンバーを募集中です。少しでもご興味あれば、アノテーション株式会社WEBサイトをご覧ください。