

• 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="automation-variables"></a>

AWS Systems Manager 自动化运行手册使用以下变量。有关如何使用这些变量的示例，请查看 `AWS-UpdateWindowsAmi` 运行手册的 JSON 源。

**查看 `AWS-UpdateWindowsAmi` 运行手册的 JSON 源**

1. 访问 [https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/)，打开 AWS Systems Manager 控制台。

1. 在导航窗格中，选择**文档**。

1. 在文档列表中，使用“搜索栏”或“搜索栏”右侧的数字选择运行手册 `AWS-UpdateWindowsAmi`。

1. 选择**内容**选项卡。

**系统变量**  
自动化运行手册目前支持以下系统变量。


****  

| Variable | 详细信息 | 
| --- | --- | 
|  `global:ACCOUNT_ID`  |  在其中运行自动化的用户或角色的 AWS 账户 ID。  | 
|  `global:DATE`  |  格式为 yyyy-MM-dd 的日期（运行时间）。  | 
|  `global:DATE_TIME`  |  格式为 yyyy-MM-dd\$1HH.mm.ss 的日期和时间（运行时间）。  | 
|  `global:AWS_PARTITION`  |  资源所处的分区。对于标准 AWS 区域，分区是 `aws`。对于位于其他分区中的资源，则分区是 `aws-partitionname`。例如，AWS GovCloud (US-West) 区域中资源的区域为 `aws-us-gov`。  | 
|  `global:REGION`  |  运行手册在其中运行的区域。例如，us-east-2。  | 

**自动化变量**  
自动化运行手册支持以下自动化变量。


****  

| Variable | 详细信息 | 
| --- | --- | 
|  `automation:EXECUTION_ID`  |  分配给当前自动化的唯一标识符。例如，`1a2b3c-1a2b3c-1a2b3c-1a2b3c1a2b3c1a2b3c`。  | 

**Topics**
+ [术语](#automation-terms)
+ [支持的场景](#automation-variables-support)
+ [不支持的场景](#automation-variables-unsupported)

## 术语
<a name="automation-terms"></a>

以下术语描述了如何解析变量和参数。


****  

| 租期 | 定义 | 示例 | 
| --- | --- | --- | 
|  常量 ARN  |  无变量的有效 Amazon Resource Name (ARN)。  |  `arn:aws:iam::123456789012:role/roleName`  | 
|  运行手册参数  |  在运行手册级别定义的参数（例如 `instanceId`）。可在替换基本字符串时使用该参数。系统会在启动执行时间提供该参数的值。  |  <pre>{ <br />   "description": "Create Image Demo",<br />   "version": "0.3",<br />   "assumeRole": "Your_Automation_Assume_Role_ARN",<br />   "parameters":{ <br />      "instanceId": { <br />         "type": "String",<br />         "description": "Instance to create image from"<br />   }<br />}</pre>  | 
|  系统变量  |  在评估运行手册的任何部分时，被替换到运行手册中的常规变量。  |  <pre>"activities": [ <br />   { <br />      "id": "copyImage",<br />      "activityType": "AWS-CopyImage",<br />      "maxAttempts": 1,<br />      "onFailure": "Continue",<br />      "inputs": { <br />         "ImageName": "{{imageName}}",<br />         "SourceImageId": "{{sourceImageId}}",<br />         "SourceRegion": "{{sourceRegion}}",<br />         "Encrypted": true,<br />         "ImageDescription": "Test CopyImage Description created on {{global:DATE}}"<br />      }<br />   }<br />]</pre>  | 
|  自动化变量  |  在评估运行手册的任何部分时，被替换到运行手册中且与自动化执行相关的变量。  |  <pre>{ <br />   "name": "runFixedCmds",<br />   "action": "aws:runCommand",<br />   "maxAttempts": 1,<br />   "onFailure": "Continue",<br />   "inputs": { <br />      "DocumentName": "AWS-RunPowerShellScript",<br />      "InstanceIds": [ <br />         "{{LaunchInstance.InstanceIds}}"<br />      ],<br />      "Parameters": { <br />         "commands": [ <br />            "dir",<br />            "date",<br />            "“{{outputFormat}}” -f “left”,”right”,”{{global:DATE}}”,”{{automation:EXECUTION_ID}}”<br />         ]<br />      }<br />   }<br />}</pre>  | 
|  Systems Manager 参数  |  在 AWS Systems Manager Parameter Store 内定义的变量。该参数不能在步骤输入中直接引用。访问该参数可能需要权限。  |  <pre><br />description: Launch new Windows test instance<br />schemaVersion: '0.3'<br />assumeRole: '{{AutomationAssumeRole}}'<br />parameters:<br />  AutomationAssumeRole:<br />    type: String<br />    default: ''<br />    description: >-<br />      (Required) The ARN of the role that allows Automation to perform the<br />      actions on your behalf. If no role is specified, Systems Manager<br />      Automation uses your IAM permissions to run this runbook.<br />  LatestAmi:<br />    type: String<br />    default: >-<br />      {{ssm:/aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base}}<br />    description: The latest Windows Server 2016 AMI queried from the public parameter.<br />mainSteps:<br />  - name: launchInstance<br />    action: 'aws:runInstances'<br />    maxAttempts: 3<br />    timeoutSeconds: 1200<br />    onFailure: Abort<br />    inputs:<br />      ImageId: '{{LatestAmi}}'<br />...</pre>  | 

## 支持的场景
<a name="automation-variables-support"></a>


****  

| 场景 | 注释 | 示例 | 
| --- | --- | --- | 
|  创建时的常量 ARN `assumeRole`。  |  执行授权检查来验证是否允许调用用户传递给定的 `assumeRole`。  |  <pre>{<br />  "description": "Test all Automation resolvable parameters",<br />  "schemaVersion": "0.3",<br />  "assumeRole": "arn:aws:iam::123456789012:role/roleName",<br />  "parameters": { <br />  ...</pre>  | 
|  启动自动化时为 `AssumeRole` 提供的运行手册参数。  |  必须在运行手册的参数列表中定义。  |  <pre>{<br />  "description": "Test all Automation resolvable parameters",<br />  "schemaVersion": "0.3",<br />  "assumeRole": "{{dynamicARN}}",<br />  "parameters": {<br /> ...</pre>  | 
|  启动时为运行手册参数提供的值。  |  客户提供要用于参数的值。需在运行手册的参数列表中定义在启动时提供的所有输入。  |  <pre>...<br />"parameters": {<br />    "amiId": {<br />      "type": "String",<br />      "default": "ami-12345678",<br />      "description": "list of commands to run as part of first step"<br />    },<br />...</pre> “启动自动化执行”的输入包括：`{"amiId" : ["ami-12345678"] }`  | 
|  在运行手册内容中引用的 Systems Manager 参数。  |  变量存在于客户账户中，或者是公开访问的参数，并且运行手册的 `AssumeRole` 有权访问该变量。创建时将执行检查，以确认 `AssumeRole` 都不能访问它。不能在步骤输入中直接引用参数。  |  <pre><br />...<br />parameters:<br />    LatestAmi:<br />    type: String<br />    default: >-<br />      {{ssm:/aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base}}<br />    description: The latest Windows Server 2016 AMI queried from the public parameter.<br />mainSteps:<br />  - name: launchInstance<br />    action: 'aws:runInstances'<br />    maxAttempts: 3<br />    timeoutSeconds: 1200<br />    onFailure: Abort<br />    inputs:<br />      ImageId: '{{LatestAmi}}'<br />...</pre>  | 
|  在步骤定义中引用的系统变量  |  启动自动化时被替换到运行手册中的系统变量。注入到运行手册中的值与替换发生的时间相关。换言之，由于在运行步骤之间需要花费一定时间，因此在步骤 1 中注入的时间变量的值将与在步骤 3 中注入的值不同。无需在运行手册的参数列表中设置系统变量。  |  <pre>...<br />  "mainSteps": [<br />    {<br />      "name": "RunSomeCommands",<br />      "action": "aws:runCommand",<br />      "maxAttempts": 1,<br />      "onFailure": "Continue",<br />      "inputs": {<br />        "DocumentName": "AWS:RunPowerShell",<br />        "InstanceIds": ["{{LaunchInstance.InstanceIds}}"],<br />        "Parameters": {<br />            "commands" : [<br />                "echo {The time is now {{global:DATE_TIME}}}"<br />            ]<br />        }<br />    }<br />}, ... </pre>  | 
|  在步骤定义中引用的自动化变量。  |  无需在运行手册的参数列表中设置自动化变量。唯一的受支持自动化变量是 **自动化:EXECUTION\$1ID**。  |  <pre>...<br />"mainSteps": [<br />    {<br />      "name": "invokeLambdaFunction",<br />      "action": "aws:invokeLambdaFunction",<br />      "maxAttempts": 1,<br />      "onFailure": "Continue",<br />      "inputs": {<br />        "FunctionName": "Hello-World-LambdaFunction",<br /><br />"Payload" : "{ "executionId" : "{{automation:EXECUTION_ID}}" }"<br />      }<br />    }<br />... </pre>  | 
|  在下一步的定义中参考上一步的输出。  |  这是一个参数重定向。可使用语法 `{{stepName.OutputName}}` 引用上一步的输出。客户不能将该语法用于运行手册参数。在引用步骤运行时解决此问题。运行手册的参数中未列出该参数。  |  <pre>...<br />"mainSteps": [<br />    {<br />      "name": "LaunchInstance",<br />      "action": "aws:runInstances",<br />      "maxAttempts": 1,<br />      "onFailure": "Continue",<br />      "inputs": {<br />        "ImageId": "{{amiId}}",<br />        "MinInstanceCount": 1,<br />        "MaxInstanceCount": 2<br />      }<br />    },<br />    {<br />      "name":"changeState",<br />      "action": "aws:changeInstanceState",<br />      "maxAttempts": 1,<br />      "onFailure": "Continue",<br />      "inputs": {<br />        "InstanceIds": ["{{LaunchInstance.InstanceIds}}"],<br />        "DesiredState": "terminated"<br />      }<br />    }<br /><br />... </pre>  | 

## 不支持的场景
<a name="automation-variables-unsupported"></a>


****  

| 场景 | 注释 | 示例 | 
| --- | --- | --- | 
|  为 `assumeRole` 提供的 Systems Manager 参数创建时  |  不支持。  |  <pre>...<br /><br />{<br />  "description": "Test all Automation resolvable parameters",<br />  "schemaVersion": "0.3",<br />  "assumeRole": "{{ssm:administratorRoleARN}}",<br />  "parameters": {<br /><br />... </pre>  | 
|  步骤输入中直接引用的 Systems Manager 参数。  |  在创建时返回 `InvalidDocumentContent` 异常。  |  <pre><br />...<br />mainSteps:<br />  - name: launchInstance<br />    action: 'aws:runInstances'<br />    maxAttempts: 3<br />    timeoutSeconds: 1200<br />    onFailure: Abort<br />    inputs:<br />      ImageId: '{{ssm:/aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base}}'<br />...</pre>  | 
|  变量步骤定义  |  运行手册中步骤的定义由变量构建而成。  |  <pre>...<br /><br />"mainSteps": [<br />    {<br />      "name": "LaunchInstance",<br />      "action": "aws:runInstances",<br />      "{{attemptModel}}": 1,<br />      "onFailure": "Continue",<br />      "inputs": {<br />        "ImageId": "ami-12345678",<br />        "MinInstanceCount": 1,<br />        "MaxInstanceCount": 2<br />      }<br /><br />...<br /><br />User supplies input : { "attemptModel" : "minAttempts" } </pre>  | 
|  交叉引用运行手册参数  |  用户在启动时提供了输入参数，而该参数引用了运行手册中的另一参数。  |  <pre>...<br />"parameters": {<br />    "amiId": {<br />      "type": "String",<br />      "default": "ami-7f2e6015",<br />      "description": "list of commands to run as part of first step"<br />    },<br />    "alternateAmiId": {<br />      "type": "String",<br />      "description": "The alternate AMI to try if this first fails".<br /><br />"default" : "{{amiId}}"<br />    },<br /><br />... </pre>  | 
|  多层扩展  |  运行手册定义了评估变量名称的变量。它位于变量分隔符（即 *\$1\$1 \$1\$1*）内，并扩展为变量/参数的值。  |  <pre>...<br />  "parameters": {<br />    "firstParameter": {<br />      "type": "String",<br />      "default": "param2",<br />      "description": "The parameter to reference"<br />    },<br />    "secondParameter": {<br />      "type": "String",<br />      "default" : "echo {Hello world}",<br />      "description": "What to run"<br />    }<br />  },<br />  "mainSteps": [{<br />      "name": "runFixedCmds",<br />      "action": "aws:runCommand",<br />      "maxAttempts": 1,<br />      "onFailure": "Continue",<br />      "inputs": {<br />        "DocumentName": "AWS-RunPowerShellScript",<br /><br />"InstanceIds" : "{{LaunchInstance.InstanceIds}}",<br />        "Parameters": {<br />          "commands": [ "{{ {{firstParameter}} }}"]<br /><br />}<br /><br />...<br /><br />Note: The customer intention here would be to run a command of "echo {Hello world}" </pre>  | 
|  引用属于不同变量类型的运行手册步骤的输出  |  用户在后续步骤中引用前面运行手册步骤的输出。输出是一个不符合后续步骤中的操作要求的变量类型。  |  <pre>...<br />mainSteps:<br />- name: getImageId<br />  action: aws:executeAwsApi<br />  inputs:<br />    Service: ec2<br />    Api: DescribeImages<br />    Filters:  <br />    - Name: "name"<br />      Values: <br />      - "{{ImageName}}"<br />  outputs:<br />  - Name: ImageIdList<br />    Selector: "$.Images"<br />    Type: "StringList"<br />- name: copyMyImages<br />  action: aws:copyImage<br />  maxAttempts: 3<br />  onFailure: Abort<br />  inputs:<br />    SourceImageId: {{getImageId.ImageIdList}}<br />    SourceRegion: ap-northeast-2<br />    ImageName: Encrypted Copies of LAMP base AMI in ap-northeast-2<br />    Encrypted: true <br />... <br />Note: You must provide the type required by the Automation action. <br />In this case, aws:copyImage requires a "String" type variable but the preceding step outputs a "StringList" type variable.<br />                                        </pre>  | 