チュートリアル: CLI を使用したインベントリ用のマネージドノードの設定 - AWS Systems Manager

チュートリアル: CLI を使用したインベントリ用のマネージドノードの設定

以下の手順では、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)

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

AWS アカウント 内および現在のリージョン内のすべてのマネージドノードのインベントリを設定するには (CLI)
  1. まだ AWS Command Line Interface (AWS CLI) をインストールして設定していない場合は、インストールして設定します。

    詳細については、「AWS CLI の最新バージョンをインストールまたは更新します。」を参照してください。

  2. 以下のコマンドを実行します。

    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)

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

マネージドノードをインベントリ用に手動設定するには (CLI)
  1. まだ AWS Command Line Interface (AWS CLI) をインストールして設定していない場合は、インストールして設定します。

    詳細については、「AWS CLI の最新バージョンをインストールまたは更新します。」を参照してください。

  2. 以下のコマンドを実行して、ノードで 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\": \"DOC-EXAMPLE-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\": \"DOC-EXAMPLE-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\": \"DOC-EXAMPLE-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\": \"DOC-EXAMPLE-BUCKET\", \"OutputS3KeyPrefix\": \"Test\" } }" ^ --parameters "networkConfig=Enabled,windowsUpdates=Enabled,applications=Enabled"

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

    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
  3. 以下のコマンドを実行して、関連付けステータスを表示します。

    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"
            }
    ]
    }