AWS Systems Manager
用户指南
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 Amazon AWS 入门

SSM 文档语法

文档语法由用于创建文档的架构版本定义。我们建议您使用 2.2 版或更高版本的架构。使用此架构版本的文档包含以下顶级元素。有关可在这些元素中指定的属性的信息,请参阅顶级元素

  • schemaVersion:要使用的架构版本。

  • Description:您提供的描述文档目的的信息。

  • Parameters:文档接受的参数。对于您经常引用的参数,我们建议您在 Systems Manager Parameter Store 中存储这些参数,然后进行引用。您可以在文档的这一部分引用 StringStringList Systems Manager 参数。您不能在文档的这一部分引用 Secure String Systems Manager 参数。有关更多信息,请参阅 AWS Systems Manager Parameter Store

  • mainSteps:可以包含多个步骤 (插件) 的对象。步骤包括一个或多个操作、可选前提条件、各操作的唯一名称以及这些操作的 inputs (参数)。有关支持的插件和插件属性的列表,请参阅SSM 文档插件参考

    重要

    操作的名称不能包含空格。如果名称包含空格,您将收到 InvalidDocumentContent 错误。

架构版本 2.2

以下示例以 JSON 格式显示 2.2 版架构文档的顶级元素。

{ "schemaVersion":"2.2", "description":"A description of the document.", "parameters":{ "parameter 1":{ "one or more parameter properties" }, "parameter 2":{ "one or more parameter properties" }, "parameter 3":{ "one or more parameter properties" } }, "mainSteps":[ { "action":"plugin 1", "name":"A name for this action.", "inputs":{ "name":"{{ input 1 }}", "name":"{{ input 2 }}", "name":"{{ input 3 }}", } } ] }

YAML 架构版本 2.2 示例

您可以将以下 YAML 文档用于 Run Command 以返回一个或多个实例的主机名称。

--- schemaVersion: '2.2' description: Sample document mainSteps: - action: aws:runPowerShellScript name: runPowerShellScript inputs: runCommand: - hostname

架构版本 2.2 前提条件参数示例

2.2 版架构提供跨平台支持。这意味着在一个 SSM 文档内,您可以为不同的插件指定不同的操作系统。跨平台支持在某个步骤中使用 precondition 参数,如下例所示。

{ "schemaVersion":"2.2", "description":"cross-platform sample", "mainSteps":[ { "action":"aws:runPowerShellScript", "name":"PatchWindows", "precondition":{ "StringEquals":[ "platformType", "Windows" ] }, "inputs":{ "runCommand":[ "cmds" ] } }, { "action":"aws:runShellScript", "name":"PatchLinux", "precondition":{ "StringEquals":[ "platformType", "Linux" ] }, "inputs":{ "runCommand":[ "cmds" ] } } ] }

架构版本示例 2.2

您可以将以下 YAML 文档用于 状态管理器 以下载并安装 ClamAV 防病毒软件。状态管理器 强制实施特定配置,这意味着每次运行 状态管理器 关联时,系统会检查是否安装了 ClamAV 软件。如果未安装,状态管理器 会重新运行本文档。

--- schemaVersion: '2.2' description: State Manager Bootstrap Example parameters: {} mainSteps: - action: aws:runShellScript name: configureServer inputs: runCommand: - sudo yum install -y httpd24 - sudo yum --enablerepo=epel install -y clamav

架构版本 2.0 YAML 清单示例

您可以将以下 YAML 文档用于 状态管理器 以收集关于实例的清单元数据。

--- schemaVersion: '2.2' description: Software Inventory Policy Document. parameters: applications: type: String default: Enabled description: "(Optional) Collect data for installed applications." allowedValues: - Enabled - Disabled awsComponents: type: String default: Enabled description: "(Optional) Collect data for AWS Components like amazon-ssm-agent." allowedValues: - Enabled - Disabled networkConfig: type: String default: Enabled description: "(Optional) Collect data for Network configurations." allowedValues: - Enabled - Disabled windowsUpdates: type: String default: Enabled description: "(Optional) Collect data for all Windows Updates." allowedValues: - Enabled - Disabled instanceDetailedInformation: type: String default: Enabled description: "(Optional) Collect additional information about the instance, including the CPU model, speed, and the number of cores, to name a few." allowedValues: - Enabled - Disabled customInventory: type: String default: Enabled description: "(Optional) Collect data for custom inventory." allowedValues: - Enabled - Disabled mainSteps: - action: aws:softwareInventory name: collectSoftwareInventoryItems inputs: applications: "{{ applications }}" awsComponents: "{{ awsComponents }}" networkConfig: "{{ networkConfig }}" windowsUpdates: "{{ windowsUpdates }}" instanceDetailedInformation: "{{ instanceDetailedInformation }}" customInventory: "{{ customInventory }}"

架构版本 2.2 AWS-ConfigureAWSPackage 示例

以下示例显示 AWS-ConfigureAWSPackage 文档。mainSteps 部分在 action 步骤中包括 aws:configurePackage 插件。

{ "schemaVersion": "2.2", "description": "Install or uninstall the latest version or specified version of an AWS package. Available packages include the following: AWSPVDriver, AwsEnaNetworkDriver, IntelSriovDriver, AwsVssComponents, and AmazonCloudWatchAgent, and AWSSupport-EC2Rescue.", "parameters": { "action": { "description": "(Required) Specify whether or not to install or uninstall the package.", "type": "String", "allowedValues": [ "Install", "Uninstall" ] }, "name": { "description": "(Required) The package to install/uninstall.", "type": "String", "allowedPattern": "^arn:[a-z0-9][-.a-z0-9]{0,62}:[a-z0-9][-.a-z0-9]{0,62}:([a-z0-9] [-.a-z0-9]{0,62})?:([a-z0-9][-.a-z0-9]{0,62})?:package\\/[a-zA-Z][a-zA-Z0-9\\-_]{0,39}$|^ [a-zA-Z][a-zA-Z0-9\\-_]{0,39}$" }, "version": { "description": "(Optional) A specific version of the package to install or uninstall. If installing, the system installs the latest published version, by default. If uninstalling, the system uninstalls the currently installed version, by default. If no installed version is found, the latest published version is downloaded, and the uninstall action is run.", "type": "String", "default": "latest" } }, "mainSteps": [{ "action": "aws:configurePackage", "name": "configurePackage", "inputs": { "name": "{{ name }}", "action": "{{ action }}", "version": "{{ version }}" } }] }

架构版本 1.2

以下示例显示 1.2 版架构文档的顶级元素。

{ "schemaVersion":"1.2", "description":"A description of the Systems Manager document.", "parameters":{ "parameter 1":{ "one or more parameter properties" }, "parameter 2":{ "one or more parameter properties" }, "parameter 3":{ "one or more parameter properties" } }, "runtimeConfig":{ "plugin 1":{ "properties":[ { "one or more plugin properties" } ] } } }

1.2 版架构示例

以下示例显示 AWS-RunShellScript Systems Manager 文档。runtimeConfig 部分包含 aws:runShellScript 插件。

{ "schemaVersion":"1.2", "description":"Run a shell script or specify the commands to run.", "parameters":{ "commands":{ "type":"StringList", "description":"(Required) Specify a shell script or a command to run.", "minItems":1, "displayType":"textarea" }, "workingDirectory":{ "type":"String", "default":"", "description":"(Optional) The path to the working directory on your instance.", "maxChars":4096 }, "executionTimeout":{ "type":"String", "default":"3600", "description":"(Optional) The time in seconds for a command to complete before it is considered to have failed. Default is 3600 (1 hour). Maximum is 172800 (48 hours).", "allowedPattern":"([1-9][0-9]{0,3})|(1[0-9]{1,4})|(2[0-7][0-9]{1,3})|(28[0-7][0-9]{1,2})|(28800)" } }, "runtimeConfig":{ "aws:runShellScript":{ "properties":[ { "id":"0.aws:runShellScript", "runCommand":"{{ commands }}", "workingDirectory":"{{ workingDirectory }}", "timeoutSeconds":"{{ executionTimeout }}" } ] } } }