

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用適用於 AMS Accelerate 的 Systems Manager 命令列界面 (CLI) 建立維護時段
<a name="acc-p-maint-window-cli"></a>

若要使用命令列界面建立 AMS Accelerate 維護時段：

1. 遵循 SSM [ 教學課程：建立和設定維護時段 (AWS CLI)](https://docs.aws.amazon.com/systems-manager/latest/userguide/maintenance-windows-cli-tutorials-create.html)。對於教學課程的每個步驟，以下是用於修補的範例 CLI 命令。
**注意**  
 這些範例專屬於 Linux 或 macOS。命令也可以從中執行 AWS CloudShell ，其可能比`awscli`在本機電腦上設定更簡單。如需詳細資訊，請參閱[使用 AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/working-with-cloudshell.html) 。

   1. 在教學課程的步驟 1 中，若要建立維護時段：

      ```
      aws ssm create-maintenance-window \
                      --name Sample-Maintenance-Window \
                      --schedule "cron(0 30 23 ? * TUE#2 *)" \
                      --duration 4 \
                      --cutoff 1 \
                      --allow-unassociated-targets \
                      --tags "Key=Environment,Value=Production"
      ```

      成功完成時，`window-id`會傳回 。

   1. 在教學課程的步驟 2 中，註冊目標節點：

      ```
      aws ssm register-target-with-maintenance-window \
                      --window-id "mw-{{xxxxxxxxx}}" \
                      --resource-type "INSTANCE" \
                      --target "Key=tag:Environment,Values=Prod"
      ```

      成功完成時，會傳回 `WindowTargetID`。

   1. 在教學課程的步驟 3 中，註冊任務：

      ```
      aws ssm register-task-with-maintenance-window \
          --window-id "mw-{{xxxxxx}}" \
          --targets "Key=WindowTargetIds,Values={{63d4f63c-xxxxxx-9b1d-xxxxxfff}}" \
          --task-arn "AWSManagedServices-PatchInstance" \
          --service-role-arn "arn:aws:iam::{{AWS-Account-ID}}:role/ams_ssm_automation_role" \
          --task-invocation-parameters "{\"Automation\":{\"DocumentVersion\":\"\$DEFAULT\",\"Parameters\":{\"InstanceId\":[\"{{{{TARGET_ID}}}}\"],\"StartInactiveInstances\":[\"True\"]}}}" \
          --max-concurrency 50 \
          --max-errors 50 \
          --name "AutomationExample" \
          --description "Sample Description" \
          --task-type=AUTOMATION
      ```