関連付けの編集と新しいバージョンの作成 - AWS Systems Manager

関連付けの編集と新しいバージョンの作成

State Manager の関連付けを編集して、新しい名前、スケジュール、重大度レベル、ターゲット、またはその他の値を指定できます。SSM Command タイプのドキュメントに基づく関連付けについては、コマンドの出力を Amazon Simple Storage Service (Amazon S3) バケットに書き込むことも選択できます。関連付けを編集した後、State Manager で新しいバージョンが作成されます。編集後、次の手順で説明しているように、複数のバージョンを表示できます。

次の手順では、Systems Manager コンソール、AWS Command Line Interface (AWS CLI)、および AWS Tools for PowerShell (Tools for PowerShell) を使用して、関連付けの新しいバージョンを編集および作成する方法について説明します。

重要

ドキュメントが別のアカウントから共有されている場合、State Manager は、そのドキュメントの新しいバージョンを使用する関連付けの実行をサポートしません。Systems Manager コンソールに新しいバージョンが処理されたことが表示されている場合でも、別のアカウントから共有されているときは、State Manager は、常にドキュメントの default バージョンを実行します。別なアカウントから共有されたドキュメントの新しいバージョンを使用して関連付けを実行する場合、ドキュメントバージョンを default に設定する必要があります。

関連付けを編集する (コンソール)

次の手順では、Systems Manager コンソールを使用して、関連付けの新しいバージョンを編集および作成する方法について説明します。

注記

Automation ランブックではなく、SSM Command ドキュメントを使用する関連付けの場合、この手順では既存の Amazon S3 バケットへの書き込みアクセス権が必要になります。Amazon S3 を初めて使用する場合は、Amazon S3 の使用料金が発生することに留意してください。バケットを作成する方法については、「バケットの作成」を参照してください。

State Manager の関連付けを編集するには
  1. AWS Systems Manager コンソール (https://console.aws.amazon.com/systems-manager/) を開きます。

  2. ナビゲーションペインで、[State Manager] を選択します。

  3. 既存の関連付けを選択してから、[編集] を選択します。

  4. 現在の要件を満たすように関連付けを再設定します。

    Command および Policy ドキュメントを使用した関連付けのオプションについては、「関連付けの作成」を参照してください。Automation ランブックを使用した関連付けのオプションについては、「State Manager 関連付けでのオートメーションのスケジュール設定」を参照してください。

  5. [Save Changes] を選択します。

  6. (オプション) 関連付け情報を表示するには、[関連付け] ページで編集した関連付けの名前を選択してから、[バージョン] タブを選択します。システムが、作成および編集した関連付けの各バージョンを一覧表示します。

  7. (オプション) SSM Command ドキュメントに基づく関連付けの出力を表示するには、次の手順を実行します。

    1. https://console.aws.amazon.com/s3/ で Amazon S3 コンソールを開きます。

    2. コマンド出力の保存先として指定した Amazon S3 バケットの名前を選択し、関連付けを実行したノードの ID を使用して名前を付けたフォルダを選択します (出力の保存先としてバケット内のフォルダを選択した場合は、最初にそのフォルダを開きます)。

    3. awsrunPowerShell フォルダで数レベルをドリルダウンして、stdout ファイルを見つけます。

    4. [Open] または [Download] を選択してホスト名を表示します。

関連付けを編集する (コマンドライン)

次の手順では、AWS CLI (Linux または Windows の場合) または AWS Tools for PowerShell を使用して、関連付けの新しいバージョンを編集および作成する方法について説明します。

State Manager の関連付けを編集するには
  1. まだ AWS CLI または AWS Tools for PowerShell をインストールして設定していない場合は、インストールして設定します。

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

  2. 既存の State Manager 関連付けの新しいバージョンを編集および作成するコマンドを作成するには、次の形式を使用します。各リソースプレースホルダーの例をユーザー自身の情報に置き換えます。

    重要

    update-association を呼び出す場合、システムはリクエストのすべてのオプションパラメータを削除し、それらのパラメータにおいて関連付けを null 値で上書きします。これは仕様です。パラメータを変更しない場合でも、呼び出しのオプションパラメータをすべて指定する必要があります。これには --name パラメータが含まれます。このアクションを呼び出す前に、describe-association API オペレーションを呼び出して、update-association コールに必要なすべてのオプションパラメータをメモしておくことをお勧めします。

    Linux & macOS
    aws ssm update-association \ --name document_name \ --document-version version_of_document_applied \ --instance-id instances_to_apply_association_on \ --parameters (if any) \ --targets target_options \ --schedule-expression "cron_or_rate_expression" \ --schedule-offset "number_between_1_and_6" \ --output-location s3_bucket_to_store_output_details \ --association-name association_name \ --max-errors a_number_of_errors_or_a_percentage_of_target_set \ --max-concurrency a_number_of_instances_or_a_percentage_of_target_set \ --compliance-severity severity_level \ --calendar-names change_calendar_names \ --target-locations aws_region_or_account
    Windows
    aws ssm update-association ^ --name document_name ^ --document-version version_of_document_applied ^ --instance-id instances_to_apply_association_on ^ --parameters (if any) ^ --targets target_options ^ --schedule-expression "cron_or_rate_expression" ^ --schedule-offset "number_between_1_and_6" ^ --output-location s3_bucket_to_store_output_details ^ --association-name association_name ^ --max-errors a_number_of_errors_or_a_percentage_of_target_set ^ --max-concurrency a_number_of_instances_or_a_percentage_of_target_set ^ --compliance-severity severity_level ^ --calendar-names change_calendar_names ^ --target-locations aws_region_or_account
    PowerShell
    Update-SSMAssociation ` -Name document_name ` -DocumentVersion version_of_document_applied ` -InstanceId instances_to_apply_association_on ` -Parameters (if any) ` -Target target_options ` -ScheduleExpression "cron_or_rate_expression" ` -ScheduleOffset "number_between_1_and_6" ` -OutputLocation s3_bucket_to_store_output_details ` -AssociationName association_name ` -MaxError a_number_of_errors_or_a_percentage_of_target_set -MaxConcurrency a_number_of_instances_or_a_percentage_of_target_set ` -ComplianceSeverity severity_level ` -CalendarNames change_calendar_names ` -TargetLocations aws_region_or_account

    次の例では、既存の関連付けを更新して名前を TestHostnameAssociation2 に変更します。新しい関連付けバージョンは 1 時間ごとに実行され、コマンドの出力を指定された Amazon S3 バケットに書き込みます。

    Linux & macOS
    aws ssm update-association \ --association-id 8dfe3659-4309-493a-8755-01234EXAMPLE \ --association-name TestHostnameAssociation2 \ --parameters commands="echo Association" \ --output-location S3Location='{OutputS3Region=us-east-1,OutputS3BucketName=amzn-s3-demo-bucket,OutputS3KeyPrefix=logs}' \ --schedule-expression "cron(0 */1 * * ? *)"
    Windows
    aws ssm update-association ^ --association-id 8dfe3659-4309-493a-8755-01234EXAMPLE ^ --association-name TestHostnameAssociation2 ^ --parameters commands="echo Association" ^ --output-location S3Location='{OutputS3Region=us-east-1,OutputS3BucketName=amzn-s3-demo-bucket,OutputS3KeyPrefix=logs}' ^ --schedule-expression "cron(0 */1 * * ? *)"
    PowerShell
    Update-SSMAssociation ` -AssociationId b85ccafe-9f02-4812-9b81-01234EXAMPLE ` -AssociationName TestHostnameAssociation2 ` -Parameter @{"commands"="echo Association"} ` -S3Location_OutputS3BucketName amzn-s3-demo-bucket ` -S3Location_OutputS3KeyPrefix logs ` -S3Location_OutputS3Region us-east-1 ` -ScheduleExpression "cron(0 */1 * * ? *)"

    次の例では、既存の関連付けを更新して名前を CalendarAssociation に変更します。新しい関連付けは、カレンダーが開いているときに実行され、指定された Amazon S3 バケットにコマンド出力を書き込みます。

    Linux & macOS
    aws ssm update-association \ --association-id 8dfe3659-4309-493a-8755-01234EXAMPLE \ --association-name CalendarAssociation \ --parameters commands="echo Association" \ --output-location S3Location='{OutputS3Region=us-east-1,OutputS3BucketName=amzn-s3-demo-bucket,OutputS3KeyPrefix=logs}' \ --calendar-names "arn:aws:ssm:us-east-1:123456789012:document/testCalendar2"
    Windows
    aws ssm update-association ^ --association-id 8dfe3659-4309-493a-8755-01234EXAMPLE ^ --association-name CalendarAssociation ^ --parameters commands="echo Association" ^ --output-location S3Location='{OutputS3Region=us-east-1,OutputS3BucketName=amzn-s3-demo-bucket,OutputS3KeyPrefix=logs}' ^ --calendar-names "arn:aws:ssm:us-east-1:123456789012:document/testCalendar2"
    PowerShell
    Update-SSMAssociation ` -AssociationId b85ccafe-9f02-4812-9b81-01234EXAMPLE ` -AssociationName CalendarAssociation ` -AssociationName OneTimeAssociation ` -Parameter @{"commands"="echo Association"} ` -S3Location_OutputS3BucketName amzn-s3-demo-bucket ` -CalendarNames "arn:aws:ssm:us-east-1:123456789012:document/testCalendar2"

    次の例では、既存の関連付けを更新して名前を MultiCalendarAssociation に変更します。新しい関連付けは、カレンダーが開いているときに実行され、指定された Amazon S3 バケットにコマンド出力を書き込みます。

    Linux & macOS
    aws ssm update-association \ --association-id 8dfe3659-4309-493a-8755-01234EXAMPLE \ --association-name MultiCalendarAssociation \ --parameters commands="echo Association" \ --output-location S3Location='{OutputS3Region=us-east-1,OutputS3BucketName=amzn-s3-demo-bucket,OutputS3KeyPrefix=logs}' \ --calendar-names "arn:aws:ssm:us-east-1:123456789012:document/testCalendar1" "arn:aws:ssm:us-east-2:123456789012:document/testCalendar2"
    Windows
    aws ssm update-association ^ --association-id 8dfe3659-4309-493a-8755-01234EXAMPLE ^ --association-name MultiCalendarAssociation ^ --parameters commands="echo Association" ^ --output-location S3Location='{OutputS3Region=us-east-1,OutputS3BucketName=amzn-s3-demo-bucket,OutputS3KeyPrefix=logs}' ^ --calendar-names "arn:aws:ssm:us-east-1:123456789012:document/testCalendar1" "arn:aws:ssm:us-east-2:123456789012:document/testCalendar2"
    PowerShell
    Update-SSMAssociation ` -AssociationId b85ccafe-9f02-4812-9b81-01234EXAMPLE ` -AssociationName MultiCalendarAssociation ` -Parameter @{"commands"="echo Association"} ` -S3Location_OutputS3BucketName amzn-s3-demo-bucket ` -CalendarNames "arn:aws:ssm:us-east-1:123456789012:document/testCalendar1" "arn:aws:ssm:us-east-2:123456789012:document/testCalendar2"
  3. 関連付けの新しいバージョンを表示するには、次のコマンドを実行します。

    Linux & macOS
    aws ssm describe-association \ --association-id b85ccafe-9f02-4812-9b81-01234EXAMPLE
    Windows
    aws ssm describe-association ^ --association-id b85ccafe-9f02-4812-9b81-01234EXAMPLE
    PowerShell
    Get-SSMAssociation ` -AssociationId b85ccafe-9f02-4812-9b81-01234EXAMPLE | Select-Object *

    システムが以下のような情報を返します。

    Linux & macOS
    {
        "AssociationDescription": {
            "ScheduleExpression": "cron(0 */1 * * ? *)",
            "OutputLocation": {
                "S3Location": {
                    "OutputS3KeyPrefix": "logs",
                    "OutputS3BucketName": "amzn-s3-demo-bucket",
                    "OutputS3Region": "us-east-1"
                }
            },
            "Name": "AWS-RunPowerShellScript",
            "Parameters": {
                "commands": [
                    "echo Association"
                ]
            },
            "LastExecutionDate": 1559316400.338,
            "Overview": {
                "Status": "Success",
                "DetailedStatus": "Success",
                "AssociationStatusAggregatedCount": {}
            },
            "AssociationId": "b85ccafe-9f02-4812-9b81-01234EXAMPLE",
            "DocumentVersion": "$DEFAULT",
            "LastSuccessfulExecutionDate": 1559316400.338,
            "LastUpdateAssociationDate": 1559316389.753,
            "Date": 1559314038.532,
            "AssociationVersion": "2",
            "AssociationName": "TestHostnameAssociation2",
            "Targets": [
                {
                    "Values": [
                        "Windows"
                    ],
                    "Key": "tag:Environment"
                }
            ]
        }
    }
    Windows
    {
        "AssociationDescription": {
            "ScheduleExpression": "cron(0 */1 * * ? *)",
            "OutputLocation": {
                "S3Location": {
                    "OutputS3KeyPrefix": "logs",
                    "OutputS3BucketName": "amzn-s3-demo-bucket",
                    "OutputS3Region": "us-east-1"
                }
            },
            "Name": "AWS-RunPowerShellScript",
            "Parameters": {
                "commands": [
                    "echo Association"
                ]
            },
            "LastExecutionDate": 1559316400.338,
            "Overview": {
                "Status": "Success",
                "DetailedStatus": "Success",
                "AssociationStatusAggregatedCount": {}
            },
            "AssociationId": "b85ccafe-9f02-4812-9b81-01234EXAMPLE",
            "DocumentVersion": "$DEFAULT",
            "LastSuccessfulExecutionDate": 1559316400.338,
            "LastUpdateAssociationDate": 1559316389.753,
            "Date": 1559314038.532,
            "AssociationVersion": "2",
            "AssociationName": "TestHostnameAssociation2",
            "Targets": [
                {
                    "Values": [
                        "Windows"
                    ],
                    "Key": "tag:Environment"
                }
            ]
        }
    }
    PowerShell
    AssociationId                 : b85ccafe-9f02-4812-9b81-01234EXAMPLE
    AssociationName               : TestHostnameAssociation2
    AssociationVersion            : 2
    AutomationTargetParameterName : 
    ComplianceSeverity            : 
    Date                          : 5/31/2019 2:47:18 PM
    DocumentVersion               : $DEFAULT
    InstanceId                    : 
    LastExecutionDate             : 5/31/2019 3:26:40 PM
    LastSuccessfulExecutionDate   : 5/31/2019 3:26:40 PM
    LastUpdateAssociationDate     : 5/31/2019 3:26:29 PM
    MaxConcurrency                : 
    MaxErrors                     : 
    Name                          : AWS-RunPowerShellScript
    OutputLocation                : Amazon.SimpleSystemsManagement.Model.InstanceAssociationOutputLocation
    Overview                      : Amazon.SimpleSystemsManagement.Model.AssociationOverview
    Parameters                    : {[commands, Amazon.Runtime.Internal.Util.AlwaysSendList`1[System.String]]}
    ScheduleExpression            : cron(0 */1 * * ? *)
    Status                        : 
    Targets                       : {tag:Environment}