

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

# 還原至先前的 AWS Systems Manager 文件版本
<a name="tutorials_08_ssm-document-version-rev-v3"></a>

了解如何還原至先前的 AWS Systems Manager 文件版本。如需 SSM 文件的詳細資訊，請參閱 [AWS Systems Manager 使用者指南](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-ssm-docs.html)*AWS 中的 Systems Manager* 文件。

使用 AWS ParallelCluster 命令列界面 (CLI) 或 API 時，您只需為建立或更新 AWS ParallelCluster 映像和叢集時建立 AWS 的資源付費。如需詳細資訊，請參閱[AWS 使用的 服務 AWS ParallelCluster](aws-services-v3.md)。

**事前準備：**
+  AWS 帳戶 具有管理 SSM 文件許可的 。
+  AWS CLI [已安裝並設定 。](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)

## 還原至先前的 SSM 文件版本
<a name="tutorials_08_ssm-document-version-rev-steps"></a>

1. 在終端機中，執行下列命令以取得您擁有的現有 SSM 文件清單。

   ```
   $ aws ssm list-documents --document-filter "key=Owner,value=Self"
   ```

1. 將 SSM 文件還原至先前的版本。在此範例中，我們會還原至`SessionManagerRunShell`文件的先前版本。您可以使用 SSM `SessionManagerRunShell` 文件來自訂您啟動的每個 SSM shell 工作階段。

   1. `SessionManagerRunShell` 執行下列命令來尋找 的 `DocumentVersion` 參數：

      ```
      $ aws ssm describe-document --name "SSM-SessionManagerRunShell"
      {
          "Document": {
              "Hash": "...",
              "HashType": "Sha256",
              "Name": "SSM-SessionManagerRunShell",
              "Owner": "123456789012",
              "CreatedDate": "2023-02-20T19:04:32.390000+00:00",
              "Status": "Active",
              "DocumentVersion": "1",
              "Parameters": [
                  {
                      "Name": "linuxcmd",
                      "Type": "String",
                      "Description": "The command to run on connection...",
                      "DefaultValue": "if [ -d '/opt/parallelcluster' ]; then source /opt/parallelcluster/cfnconfig; sudo su - $cfn_cluster_user; fi; /bin/bash"
                  }
              ],
              "PlatformTypes": [
                  "Windows",
                  "Linux",
                  "MacOS"
              ],
              "DocumentType": "Session",
              "SchemaVersion": "1.0",
              "LatestVersion": "2",
              "DefaultVersion": "1",
              "DocumentFormat": "JSON",
              "Tags": []
          }
      }
      ```

      最新版本為 `2`。

   1. 執行下列命令以還原至先前的版本：

      ```
      $ aws ssm delete-document --name "SSM-SessionManagerRunShell" --document-version 2
      ```

1. 再次執行 `describe-document`命令，確認文件版本已還原：

   ```
   $ aws ssm describe-document --name "SSM-SessionManagerRunShell"
   {
       "Document": {
           "Hash": "...",
           "HashType": "Sha256",
           "Name": "SSM-SessionManagerRunShell",
           "Owner": "123456789012",
           "CreatedDate": "2023-02-20T19:04:32.390000+00:00",
           "Status": "Active",
           "DocumentVersion": "1",
           "Parameters": [
               {
                   "Name": "linuxcmd",
                   "Type": "String",
                   "Description": "The command to run on connection...",
                   "DefaultValue": "if [ -d '/opt/parallelcluster' ]; then source /opt/parallelcluster/cfnconfig; sudo su - $cfn_cluster_user; fi; /bin/bash"
               }
           ],
           "PlatformTypes": [
               "Windows",
               "Linux",
               "MacOS"
           ],
           "DocumentType": "Session",
           "SchemaVersion": "1.0",
           "LatestVersion": "1",
           "DefaultVersion": "1",
           "DocumentFormat": "JSON",
           "Tags": []
       }
   }
   ```

   最新版本為 `1`。