

• AWS Systems Manager CloudWatch ダッシュボードは、2026 年 4 月 30 日以降は利用できなくなります。お客様は、これまでと同様に Amazon CloudWatch コンソールを使用して、Amazon CloudWatch ダッシュボードの表示、作成、管理を継続できます。詳細については、「[Amazon CloudWatch ダッシュボードのドキュメント](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)」を参照してください。

# AWS CLI を使用してインベントリデータ収集を設定する
<a name="inventory-collection-cli"></a>

以下の手順では、AWS Systems Manager インベントリを設定してマネージドノードからメタデータを収集するプロセスについて、順を追って説明します。インベントリ収集の設定を開始するには、Systems Manager State Manager の関連付けを作成します。関連付けが実行されると、Systems Manager はインベントリデータを収集します。最初に関連付けを作成せずに、Systems Manager Run Command などを使用して `aws:softwareInventory` プラグインを呼び出そうとすると、次のエラーが返されます。

`The aws:softwareInventory plugin can only be invoked via ssm-associate`.

**注記**  
ノードには、一度に 1 つのインベントリのみ関連付けることができます。ノードに 2 つ以上インベントリの関連付けを設定した場合、その関連付けは実行されず、インベントリデータは収集されません。

## すべてのマネージドノードをインベントリ用にすばやく設定する (CLI)
<a name="inventory-collection-cli-all"></a>

AWS アカウント 内および現在のリージョン内のすべてのマネージドノードをすばやく設定して、インベントリデータを収集できます。これはグローバルインベントリの関連付けの作成と呼ばれます。AWS CLI を使用してグローバルなインベントリの関連付けを作成するには、次の手順に示すように、`instanceIds` 値のワイルドカードオプションを使用します。

**AWS アカウント 内および現在のリージョン内のすべてのマネージドノードのインベントリを設定するには (CLI)**

1. まだ AWS Command Line Interface (AWS CLI) をインストールして設定していない場合は、インストールして設定します。

   詳細については、「[AWS CLI の最新バージョンをインストールまたは更新します。](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)」を参照してください。

1. 以下のコマンドを実行してください。

------
#### [ Linux & macOS ]

   ```
   aws ssm create-association \
   --name AWS-GatherSoftwareInventory \
   --targets Key=InstanceIds,Values=* \
   --schedule-expression "rate(1 day)" \
   --parameters applications=Enabled,awsComponents=Enabled,customInventory=Enabled,instanceDetailedInformation=Enabled,networkConfig=Enabled,services=Enabled,windowsRoles=Enabled,windowsUpdates=Enabled
   ```

------
#### [ Windows ]

   ```
   aws ssm create-association ^
   --name AWS-GatherSoftwareInventory ^
   --targets Key=InstanceIds,Values=* ^
   --schedule-expression "rate(1 day)" ^
   --parameters applications=Enabled,awsComponents=Enabled,customInventory=Enabled,instanceDetailedInformation=Enabled,networkConfig=Enabled,services=Enabled,windowsRoles=Enabled,windowsUpdates=Enabled
   ```

------

**注記**  
このコマンドでは、インベントリで Windows レジストリまたはファイルのメタデータを収集することはできません。これらのデータ型をインベントリするには、次の手順を使用します。

## マネージドノードでインベントリを手動設定する (CLI)
<a name="inventory-collection-cli-manual"></a>

ノード ID またはタグを使用して、マネージドノードに手動で AWS Systems Manager インベントリを設定するには、次の手順に従います。

**マネージドノードをインベントリ用に手動設定するには (CLI)**

1. まだ AWS Command Line Interface (AWS CLI) をインストールして設定していない場合は、インストールして設定します。

   詳細については、「[AWS CLI の最新バージョンをインストールまたは更新します。](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)」を参照してください。

1. 以下のコマンドを実行して、ノードで Systems Manager インベントリを実行する State Manager の関連付けを作成します。各*リソースプレースホルダーの例*をユーザー自身の情報に置き換えます。このコマンドは、サービスを 6 時間ごとに実行し、ノードからネットワーク設定、Windows 更新プログラム、アプリケーションメタデータを収集するように設定します。

------
#### [ Linux & macOS ]

   ```
   aws ssm create-association \
   --name "AWS-GatherSoftwareInventory" \
   --targets "Key=instanceids,Values=an_instance_ID" \
   --schedule-expression "rate(240 minutes)" \
   --output-location "{ \"S3Location\": { \"OutputS3Region\": \"region_ID, for example us-east-2\", \"OutputS3BucketName\": \"amzn-s3-demo-bucket\", \"OutputS3KeyPrefix\": \"Test\" } }" \
   --parameters "networkConfig=Enabled,windowsUpdates=Enabled,applications=Enabled"
   ```

------
#### [ Windows ]

   ```
   aws ssm create-association ^
   --name "AWS-GatherSoftwareInventory" ^
   --targets "Key=instanceids,Values=an_instance_ID" ^
   --schedule-expression "rate(240 minutes)" ^
   --output-location "{ \"S3Location\": { \"OutputS3Region\": \"region_ID, for example us-east-2\", \"OutputS3BucketName\": \"amzn-s3-demo-bucket\", \"OutputS3KeyPrefix\": \"Test\" } }" ^
   --parameters "networkConfig=Enabled,windowsUpdates=Enabled,applications=Enabled"
   ```

------

   システムから以下のような情報が返されます。

   ```
   {
       "AssociationDescription": {
           "ScheduleExpression": "rate(240 minutes)",
           "OutputLocation": {
               "S3Location": {
                   "OutputS3KeyPrefix": "Test",
                   "OutputS3BucketName": "Test bucket",
                   "OutputS3Region": "us-east-2"
               }
           },
           "Name": "The name you specified",
           "Parameters": {
               "applications": [
                   "Enabled"
               ],
               "networkConfig": [
                   "Enabled"
               ],
               "windowsUpdates": [
                   "Enabled"
               ]
           },
           "Overview": {
               "Status": "Pending",
               "DetailedStatus": "Creating"
           },
           "AssociationId": "1a2b3c4d5e6f7g-1a2b3c-1a2b3c-1a2b3c-1a2b3c4d5e6f7g",
           "DocumentVersion": "$DEFAULT",
           "LastUpdateAssociationDate": 1480544990.06,
           "Date": 1480544990.06,
           "Targets": [
               {
                   "Values": [
                      "i-02573cafcfEXAMPLE"
                   ],
                   "Key": "InstanceIds"
               }
           ]
       }
   }
   ```

   EC2 タグで `Targets` パラメータを使用することで、ノードの大規模なグループを対象にすることができます。次の例を参照してください。

------
#### [ Linux & macOS ]

   ```
   aws ssm create-association \
   --name "AWS-GatherSoftwareInventory" \
   --targets "Key=tag:Environment,Values=Production" \
   --schedule-expression "rate(240 minutes)" \
   --output-location "{ \"S3Location\": { \"OutputS3Region\": \"us-east-2\", \"OutputS3BucketName\": \"amzn-s3-demo-bucket\", \"OutputS3KeyPrefix\": \"Test\" } }" \
   --parameters "networkConfig=Enabled,windowsUpdates=Enabled,applications=Enabled"
   ```

------
#### [ Windows ]

   ```
   aws ssm create-association ^
   --name "AWS-GatherSoftwareInventory" ^
   --targets "Key=tag:Environment,Values=Production" ^
   --schedule-expression "rate(240 minutes)" ^
   --output-location "{ \"S3Location\": { \"OutputS3Region\": \"us-east-2\", \"OutputS3BucketName\": \"amzn-s3-demo-bucket\", \"OutputS3KeyPrefix\": \"Test\" } }" ^
   --parameters "networkConfig=Enabled,windowsUpdates=Enabled,applications=Enabled"
   ```

------

   Windows Server および `files` インベントリタイプと式を使用して、`windowsRegistry` ノードのファイルおよび Windows レジストリキーをインベントリすることもできます。このインベントリタイプについての詳細は、「[ファイルと Windows レジストリインベントリで作業する](inventory-file-and-registry.md)」を参照してください。

------
#### [ Linux & macOS ]

   ```
   aws ssm create-association \
   --name "AWS-GatherSoftwareInventory" \
   --targets "Key=instanceids,Values=i-0704358e3a3da9eb1" \
   --schedule-expression "rate(240 minutes)" \
   --parameters '{"files":["[{\"Path\": \"C:\\Program Files\", \"Pattern\": [\"*.exe\"], \"Recursive\": true}]"], "windowsRegistry": ["[{\"Path\":\"HKEY_LOCAL_MACHINE\\Software\\Amazon\", \"Recursive\":true}]"]}' \
   --profile dev-pdx
   ```

------
#### [ Windows ]

   ```
   aws ssm create-association ^
   --name "AWS-GatherSoftwareInventory" ^
   --targets "Key=instanceids,Values=i-0704358e3a3da9eb1" ^
   --schedule-expression "rate(240 minutes)" ^
   --parameters '{"files":["[{\"Path\": \"C:\\Program Files\", \"Pattern\": [\"*.exe\"], \"Recursive\": true}]"], "windowsRegistry": ["[{\"Path\":\"HKEY_LOCAL_MACHINE\\Software\\Amazon\", \"Recursive\":true}]"]}' ^
   --profile dev-pdx
   ```

------

1. 以下のコマンドを実行して、関連付けステータスを表示します。

   ```
   aws ssm describe-instance-associations-status --instance-id an_instance_ID
   ```

   システムから以下のような情報が返されます。

   ```
   {
   "InstanceAssociationStatusInfos": [
            {
               "Status": "Pending",
               "DetailedStatus": "Associated",
               "Name": "reInvent2016PolicyDocumentTest",
               "InstanceId": "i-1a2b3c4d5e6f7g",
               "AssociationId": "1a2b3c4d5e6f7g-1a2b3c-1a2b3c-1a2b3c-1a2b3c4d5e6f7g",
               "DocumentVersion": "1"
           }
   ]
   }
   ```