搭配使用 UpdateAssociation 與 CLI - AWS Systems Manager

搭配使用 UpdateAssociation 與 CLI

下列程式碼範例示範如何使用 UpdateAssociation

CLI
AWS CLI

範例 1:更新文件關聯

下列 update-association 範例示範以新文件版本更新關聯。

aws ssm update-association \ --association-id "8dfe3659-4309-493a-8755-0123456789ab" \ --document-version "\$LATEST"

輸出:

{ "AssociationDescription": { "Name": "AWS-UpdateSSMAgent", "AssociationVersion": "2", "Date": 1550508093.293, "LastUpdateAssociationDate": 1550508106.596, "Overview": { "Status": "Pending", "DetailedStatus": "Creating" }, "DocumentVersion": "$LATEST", "AssociationId": "8dfe3659-4309-493a-8755-0123456789ab", "Targets": [ { "Key": "tag:Name", "Values": [ "Linux" ] } ], "LastExecutionDate": 1550508094.879, "LastSuccessfulExecutionDate": 1550508094.879 } }

如需詳細資訊,請參閱《AWS Systems Manager 使用者指南中的 Editing and creating a new version of an association

範例 2:更新關聯的排程表達式

下列 update-association 範例示範更新指定關聯的排程表達式。

aws ssm update-association \ --association-id "8dfe3659-4309-493a-8755-0123456789ab" \ --schedule-expression "cron(0 0 0/4 1/1 * ? *)"

輸出:

{ "AssociationDescription": { "Name": "AWS-HelloWorld", "AssociationVersion": "2", "Date": "2021-02-08T13:54:19.203000-08:00", "LastUpdateAssociationDate": "2021-06-29T11:51:07.933000-07:00", "Overview": { "Status": "Pending", "DetailedStatus": "Creating" }, "DocumentVersion": "$DEFAULT", "AssociationId": "8dfe3659-4309-493a-8755-0123456789ab", "Targets": [ { "Key": "aws:NoOpAutomationTag", "Values": [ "AWS-NoOpAutomationTarget-Value" ] } ], "ScheduleExpression": "cron(0 0 0/4 1/1 * ? *)", "LastExecutionDate": "2021-06-26T19:00:48.110000-07:00", "ApplyOnlyAtCronInterval": false } }

如需詳細資訊,請參閱《AWS Systems Manager 使用者指南中的 Editing and creating a new version of an association

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 UpdateAssociation

PowerShell
Tools for PowerShell

範例 1:此範例示範以新文件版本更新關聯。

Update-SSMAssociation -AssociationId "93285663-92df-44cb-9f26-2292d4ecc439" -DocumentVersion "1"

輸出:

Name : AWS-UpdateSSMAgent InstanceId : Date : 3/1/2017 6:22:21 PM Status.Name : Status.Date : Status.Message : Status.AdditionalInfo :
  • 如需 API 詳細資訊,請參閱《AWS Tools for PowerShell Cmdlet 參考》中的 UpdateAssociation

如需完整的 AWS SDK 開發人員指南和程式碼範例清單,請參閱透過 AWS SDK 使用此服務。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。