Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅
中国的 Amazon Web Services 服务入门
(PDF)。
编辑和创建关联的新版本
您可以编辑 State Manager 关联以指定新名称、计划、严重级别、目标或其他值。对于基于 SSM 命令类型文档的关联,您也可以选择将命令输出写入 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 控制台编辑和创建关联的新版本。
对于使用 SSM 命令文档而非自动化运行手册的关联,此过程要求您具有对现有 Amazon S3 存储桶的写入权限。如果您之前未使用 Amazon S3,请注意使用 Amazon S3 会产生费用。有关如何创建存储桶的信息,请参阅创建存储桶。
编辑 State Manager 关联
访问 https://console.aws.amazon.com/systems-manager/,打开 Amazon Systems Manager 控制台。
在导航窗格中,选择 State Manager。
-
选择现有的关联,然后选择编辑。
-
重新配置关联以满足当前要求。
有关与 Command
和 Policy
文档的关联选项的信息,请参阅 创建关联。有关与自动化运行手册的关联选项的信息,请参阅 使用 State Manager 关联调度自动化。
-
选择 Save Changes(保存更改)。
-
(可选)若要查看关联信息,在关联页面中,选择已编辑的关联的名称,然后选择版本选项卡。系统将列出您已创建和编辑的关联的每个版本。
-
(可选)若要查看基于 SSM Command
文档的关联输出,请执行以下操作:
通过以下网址打开 Simple Storage Service(Amazon S3)控制台:https://console.aws.amazon.com/s3/。
-
选择您指定用于存储命令输出的 Simple Storage Service (Amazon S3) 存储桶的名称,然后选择以运行关联的节点的 ID 命名的文件夹。(如果您选择将输出存储在存储桶中的文件夹内,请先打开它。)
-
下拉多个级别至 stdout
文件夹中的 awsrunPowerShell
文件。
-
选择打开或下载查看主机名。
编辑关联(命令行)
以下过程介绍了如何使用 Amazon CLI(在 Linux 或 Windows 上)或 Amazon Tools for PowerShell 编辑和创建关联的新版本。
编辑 State Manager 关联
安装并配置 Amazon CLI 或 Amazon Tools for PowerShell(如果尚未执行该操作)。
有关信息,请参阅安装或更新 Amazon CLI 的最新版本以及安装 Amazon Tools for PowerShell。
-
使用以下格式创建一个命令,以编辑和创建现有 State Manager 关联的新版本。将每个示例资源占位符
替换为您自己的信息。
- 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 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"
-
要查看关联的新版本,请运行以下命令。
- 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}