編輯和建立關聯的新版本
您可以編輯 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 不支援執行使用新版文件的關聯。若是從另一個帳戶共用的,則 State Manager 一律會執行文件的 default
版本,即使 Systems Manager 主控台顯示已處理新版本。如果您想要使用從另一個帳戶共用而來的新版本文件來執行關聯,則必須將文件版本設定為 default
。
建立關聯 (主控台)
以下程序說明如何使用 Systems Manager 主控台來編輯和建立關聯的新版本。
對於使用 SSM Command 文件 (而非 Automation 執行手冊) 的關聯,此程序要求您擁有現有 Amazon S3 儲存貯體的寫入存取權。請注意,如果您未曾使用過 Amazon Simple Storage Service (Amazon S3),您將需要支付使用 Amazon Simple Storage Service (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 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"
-
若要檢視關聯的新版本,請執行以下命令。
- 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}