

• AWS Systems Manager CloudWatch 控制面板在 2026 年 4 月 30 日之后将不再可用。客户可以像现在一样继续使用 Amazon CloudWatch 控制台来查看、创建和管理其 Amazon CloudWatch 控制面板。有关更多信息，请参阅 [Amazon CloudWatch 控制面板文档](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)。

# 使用指令文档版本运行命令
<a name="run-command-version"></a>

您可以使用文档版本参数指定在运行命令时使用 AWS Systems Manager 文档的哪个版本。您可以为此参数指定以下选项之一：
+ $DEFAULT
+ $LATEST
+ 版本号

运行以下过程，使用文档版本参数运行命令。

------
#### [ Linux ]

**在本地 Linux 计算机上使用 AWS CLI 运行命令**

1. 安装并配置 AWS Command Line Interface（AWS CLI）（如果尚未执行该操作）。

   有关信息，请参阅[安装或更新 AWS CLI 的最新版本](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

1. 列出所有可用文档

   此命令将基于 AWS Identity and Access Management (IAM) 权限列出您的账户可用的所有文档。

   ```
   aws ssm list-documents
   ```

1. 运行以下命令，查看文档的不同版本。将{{文档名称}}替换为您自己的信息。

   ```
   aws ssm list-document-versions \
       --name "{{document name}}"
   ```

1. 运行以下命令，运行使用 SSM 文档版本的命令。将每个{{示例资源占位符}}替换为您自己的信息。

   ```
   aws ssm send-command \
       --document-name "AWS-RunShellScript" \
       --parameters commands="echo Hello" \
       --instance-ids {{instance-ID}} \
       --document-version '{{$LATEST}}'
   ```

------
#### [ Windows ]

**在本地 Windows 计算机上使用 AWS CLI 运行命令**

1. 安装并配置 AWS Command Line Interface（AWS CLI）（如果尚未执行该操作）。

   有关信息，请参阅[安装或更新 AWS CLI 的最新版本](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

1. 列出所有可用文档

   此命令将基于 AWS Identity and Access Management (IAM) 权限列出您的账户可用的所有文档。

   ```
   aws ssm list-documents
   ```

1. 运行以下命令，查看文档的不同版本。将{{文档名称}}替换为您自己的信息。

   ```
   aws ssm list-document-versions ^
       --name "{{document name}}"
   ```

1. 运行以下命令，运行使用 SSM 文档版本的命令。将每个{{示例资源占位符}}替换为您自己的信息。

   ```
   aws ssm send-command ^
       --document-name "AWS-RunShellScript" ^
       --parameters commands="echo Hello" ^
       --instance-ids {{instance-ID}} ^
       --document-version "{{$LATEST}}"
   ```

------
#### [ PowerShell ]

**要使用 Tools for PowerShell 运行命令，请执行以下步骤：**

1. 如果您尚未安装和配置 AWS Tools for PowerShell（适用于 Windows PowerShell 的工具），请执行这些操作。

   有关信息，请参阅[安装 AWS Tools for PowerShell](https://docs.aws.amazon.com/powershell/latest/userguide/pstools-getting-set-up.html)。

1. 列出所有可用文档

   此命令将基于 AWS Identity and Access Management (IAM) 权限列出您的账户可用的所有文档。

   ```
   Get-SSMDocumentList
   ```

1. 运行以下命令，查看文档的不同版本。将{{文档名称}}替换为您自己的信息。

   ```
   Get-SSMDocumentVersionList `
       -Name "{{document name}}"
   ```

1. 运行以下命令，运行使用 SSM 文档版本的命令。将每个{{示例资源占位符}}替换为您自己的信息。

   ```
   Send-SSMCommand `
       -DocumentName "AWS-RunShellScript" `
       -Parameter @{commands = "echo helloWorld"} `
       -InstanceIds "{{instance-ID}}" `
       -DocumentVersion {{$LATEST}}
   ```

------