

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 恢复到以前的 S AWS ystems Manager 文档版本
<a name="tutorials_08_ssm-document-version-rev-v3"></a>

了解如何恢复到以前的 S AWS ystems Manager 文档版本。有关 SSM 文档的更多信息，请参阅 *AWS Systems Manager 用户指南* 中的 [AWS Systems Manager 文档](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-ssm-docs.html)。

使用 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`。