編輯和建立關聯的新版本 - AWS Systems Manager

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

編輯和建立關聯的新版本

您可以編輯State Manager關聯來指定新名稱、排程、嚴重性層次、目標或其他值。對於以命SSM令類型文件為基礎的關聯,您也可以選擇將命令的輸出寫入 Amazon Simple Storage Service (Amazon S3) 儲存貯體。在您編輯關聯後,State Manager 會建立新的版本。您可以依照下列程序,在編輯後檢視不同版本。

下列程序說明如何使用 Systems Manager 主控台 () 和 AWS Command Line Interface AWS Tools for PowerShell (工具AWS CLI) 編輯及建立新版本的 PowerShell關聯。

重要

如果該文件是從另一個帳戶共用的,則 State Manager 不支援執行使用新版文件的關聯。若是從另一個帳戶共用的,則 State Manager 一律會執行文件的 default 版本,即使 Systems Manager 主控台顯示已處理新版本。如果您想要使用從另一個帳戶共用而來的新版本文件來執行關聯,則必須將文件版本設定為 default

建立關聯 (主控台)

以下程序說明如何使用 Systems Manager 主控台來編輯和建立關聯的新版本。

注意

對於使用 SSM Command 文件而非自動化手冊的關聯,此程序要求您具有現有 Amazon S3 儲存貯體的寫入存取權。請注意,如果您未曾使用過 Amazon Simple Storage Service (Amazon S3),您將需要支付使用 Amazon Simple Storage Service (Amazon S3) 的費用。如需建立儲存貯體的詳細資訊,請參閱建立儲存貯體

編輯 State Manager 關聯
  1. 在開啟 AWS Systems Manager 主控台https://console.aws.amazon.com/systems-manager/

  2. 在導覽窗格中,選擇 State Manager

  3. 選擇現有的關聯,然後選擇 [編輯]。

  4. 重新設定關聯以符合您目前的需求。

    如需關聯選項與CommandPolicy文件的資訊,請參閱建立關聯。如需關聯選項與自動化手冊的資訊,請參閱使用 State Manager 關聯排程自動化

  5. 選擇 Save Changes (儲存變更)。

  6. (選擇性) 若要檢視關聯資訊,請在「關聯」頁面中選擇您編輯的關聯名稱,然後選擇「版本」標籤。系統會列出您所建立和編輯的關聯的每個版本。

  7. (選擇性) 若要根據SSMCommand文件檢視關聯的輸出,請執行下列動作:

    1. 在開啟 Amazon S3 主控台https://console.aws.amazon.com/s3/

    2. 選擇您指定來存放命令輸出的 Amazon Simple Storage Service (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 關聯的新版本。替換每個 example resource placeholder 使用您自己的信息。

    重要

    當您呼叫 update-association 時,系統會從請求中卸除所有選用參數,並覆寫與這些參數之空值的關聯。這是設計本身所致。您必須在呼叫中指定所有選用參數,即使您未變更參數。這包括 --name 參數。呼叫此動作之前,我們建議您呼叫describe-association作業,並記下呼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。新的關聯版本會每個小時執行,並將命令的輸出寫入指定 Amazon Simple Storage Service (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 Simple Storage Service (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 Simple Storage Service (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}