使用指令文档版本运行命令 - AWS Systems Manager

使用指令文档版本运行命令

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

  • $DEFAULT

  • $LATEST

  • 版本号

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

Linux
在本地 Linux 计算机上使用 AWS CLI 运行命令
  1. 安装并配置 AWS Command Line Interface (AWS CLI)(如果尚未执行该操作)。

    有关信息,请参阅安装或更新 AWS CLI 的最新版本

  2. 列出所有可用文档

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

    aws ssm list-documents
  3. 运行以下命令,查看文档的不同版本。将文档名称替换为您自己的信息。

    aws ssm list-document-versions \ --name "document name"
  4. 运行以下命令,运行使用 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 的最新版本

  2. 列出所有可用文档

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

    aws ssm list-documents
  3. 运行以下命令,查看文档的不同版本。将文档名称替换为您自己的信息。

    aws ssm list-document-versions ^ --name "document name"
  4. 运行以下命令,运行使用 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

  2. 列出所有可用文档

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

    Get-SSMDocumentList
  3. 运行以下命令,查看文档的不同版本。将文档名称替换为您自己的信息。

    Get-SSMDocumentVersionList ` -Name "document name"
  4. 运行以下命令,运行使用 SSM 文档版本的命令。将每个示例资源占位符替换为您自己的信息。

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