编辑和创建关联的新版本 - Amazon Systems Manager
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

编辑和创建关联的新版本

您可以编辑 State Manager 关联以指定新名称、计划、严重级别或目标。您也可以选择将命令输出写入 Amazon Simple Storage Service (Amazon S3) 存储桶。编辑关联后,State Manager 将创建新版本。您可以在编辑后查看不同的版本,如以下过程中所述。

以下过程介绍了如何使用 Systems Manager 控制台、Amazon Command Line Interface (Amazon CLI) 和 Amazon Tools for PowerShell (Tools for PowerShell) 编辑和创建关联的新版本。

重要

如果该文档是从其他账户共享的,则 State Manager 不支持运行使用该文档的新版本的关联。如果文档是从其他账户共享的,则 State Manager 始终会运行文档的 default 版本,即使 Systems Manager 控制台显示已处理了该文档的新版本。如果要使用共享自另一个账户的文档的新版本来运行关联,则必须将文档版本设置为 default

编辑关联(控制台)

以下过程介绍了如何使用 Systems Manager 控制台编辑和创建关联的新版本。

注意

此过程要求您具有对现有 Amazon S3 存储桶的写入权限。如果您之前未使用 Amazon S3,请注意使用 Amazon S3 会产生费用。有关如何创建存储桶的信息,请参阅创建存储桶

编辑 State Manager 关联
  1. 访问 https://console.aws.amazon.com/systems-manager/,打开 Amazon Systems Manager 控制台。

  2. 在导航窗格中,选择 State Manager

    -或者-

    如果首先打开 Amazon Systems Manager 主页,选择菜单图标( 
    The menu icon
  ) 以打开导航窗格,然后选择 State Manager

  3. 选择在 创建关联(命令行) 中创建的关联,然后选择编辑

  4. Name 字段中,输入一个新名称。

  5. 指定计划部分中,选择一个新选项。

  6. (可选)对于 Output options (输出选项),要将命令输出保存到文件,请选中 Enable writing output to S3 (启用将输出写入 S3) 方框。在方框中输入存储桶和前缀(文件夹)名称。

    注意

    授予将数据写入 S3 存储桶的能力的 S3 权限,是分配给托管式节点的实例配置文件的权限,而不是执行此任务的 IAM 用户的权限。有关更多信息,请参阅为 Systems Manager 配置实例权限为混合环境创建 IAM 服务角色。此外,如果指定的 S3 存储桶位于不同的 Amazon Web Services 账户 中,请确认与该托管式节点关联的实例配置文件或 IAM 服务角色具有写入该存储桶的所需权限。

  7. 选择编辑关联。配置关联以满足当前要求。

  8. 关联页面中,选择已编辑的关联的名称,然后选择版本选项卡。系统将列出您已创建和编辑的关联的每个版本。

  9. 通过以下网址打开 Amazon S3 控制台:https://console.aws.amazon.com/s3/

  10. 选择您指定用于存储命令输出的 Simple Storage Service (Amazon S3) 存储桶的名称,然后选择以运行关联的节点的 ID 命名的文件夹。(如果您选择将输出存储在存储桶中的文件夹内,请先打开它。)

  11. 下拉多个级别至 stdout 文件夹中的 awsrunPowerShell 文件。

  12. 选择打开下载查看主机名。

编辑关联(命令行)

以下过程介绍了如何使用 Amazon CLI(在 Linux 或 Windows 上)或 Amazon Tools for PowerShell 编辑和创建关联的新版本。

编辑 State Manager 关联
  1. 安装并配置 Amazon CLI 或 Amazon Tools for PowerShell(如果尚未执行该操作)。

    有关信息,请参阅安装或更新 Amazon CLI 的最新版本以及安装 Amazon Tools for PowerShell

  2. 使用以下格式创建一个命令,以编辑和创建现有 State Manager 关联的新版本。将每个示例资源占位符替换为您自己的信息。

    重要

    当您调用 UpdateAssociation 时,系统会从请求中删除所有可选参数,并用这些参数的 null 值覆盖关联。这是设计使然。即使没有更改参数,您也必须在调用中指定所有可选参数,包括 Name 参数。在调用此 API 操作之前,建议先调用 DescribeAssociation API 操作,并记下 UpdateAssociation 调用所需的所有可选参数。

    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 "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 "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 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=DOC-EXAMPLE-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=DOC-EXAMPLE-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 DOC-EXAMPLE-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=DOC-EXAMPLE-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=DOC-EXAMPLE-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 DOC-EXAMPLE-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=DOC-EXAMPLE-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=DOC-EXAMPLE-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 DOC-EXAMPLE-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": "DOC-EXAMPLE-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": "DOC-EXAMPLE-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}