编辑和创建关联的新版本
您可以编辑 State Manager 关联以指定新名称、计划、严重级别、目标或其他值。对于基于 SSM 命令类型文档的关联,您也可以选择将命令输出写入 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 不支持运行使用该文档的新版本的关联。如果文档是从其他账户共享的,则 State Manager 始终会运行文档的 default
版本,即使 Systems Manager 控制台显示已处理了该文档的新版本。如果要使用共享自另一个账户的文档的新版本来运行关联,则必须将文档版本设置为 default
。
编辑关联(控制台)
以下过程介绍了如何使用 Systems Manager 控制台编辑和创建关联的新版本。
对于使用 SSM 命令文档而非自动化运行手册的关联,此过程要求您具有对现有 Amazon S3 存储桶的写入权限。如果您之前未使用 Amazon S3,请注意使用 Amazon S3 会产生费用。有关如何创建存储桶的信息,请参阅创建存储桶。
编辑关联(命令行)
以下过程介绍了如何使用 AWS CLI(在 Linux 或 Windows 上)或 AWS Tools for PowerShell 编辑和创建关联的新版本。
编辑 State Manager 关联
安装并配置 AWS CLI 或 AWS Tools for PowerShell(如果尚未执行该操作)。
有关信息,请参阅安装或更新 AWS CLI 的最新版本以及安装 AWS 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}