文档

ALIYUN::ECS::Command

更新时间:

ALIYUN::ECS::Command类型用于新建云助手命令。

语法

{
  "Type": "ALIYUN::ECS::Command",
  "Properties": {
    "Name": String,
    "WorkingDir": String,
    "CommandContent": String,
    "Timeout": Integer,
    "Type": String,
    "Description": String,
    "EnableParameter": Boolean,
    "Tags": List,
    "ResourceGroupId": String,
    "ContentEncoding": String
  }
}

属性

属性名称

类型

必须

允许更新

描述

约束

Name

String

命令名称。

长度为1~128个字符。支持全字符集。

WorkingDir

String

您创建的命令在ECS实例中运行的目录。

默认值:

  • Linux实例:管理员root用户的home目录下,取值为:/root

  • Windows实例:云助手客户端进程所在目录,例如C:\Windows\System32

说明

设置为其他目录时,请确保实例中存在该目录。

CommandContent

String

命令Base64编码后的内容。

命令Base64编码后的内容。

  • 该参数的值必须使用Base64编码后传输,且脚本内容的大小在Base64编码之后不能超过18KB。

  • 命令内容支持使用自定义参数形式,具体通过指定参数EnableParameter=true启用自定义参数功能:

    • 自定义参数用{{}}包含的方式定义,在{{}}内参数名前后的空格以及换行符会被忽略。

    • 自定义参数个数不能超过20个。

    • 自定义参数名允许a-zA-Z0-9-_的组合,不支持ACS::前缀指定非内置环境参数,不支持其余字符,参数名不区分大小写。

    • 单个参数名不能超过64字节。

  • 您可以指定内置环境参数作为自定义参数,执行命令时无需手动对参数赋值,云助手将为您自动替换为环境中对应的值。支持指定以下内置环境参数:

    • {{ACS::RegionId}}:地域ID。

    • {{ACS::AccountId}}:阿里云主账号UID。

    • {{ACS::InstanceId}}:实例ID。命令下发到多个实例时,如需指定{{ACS::InstanceId}}作为内置环境参数,需确保云助手Agent不低于以下版本:

      • Linux:2.2.3.309

      • Windows:2.1.3.309

    • {{ACS::InstanceName}}:实例名称。命令下发到多个实例时,如需指定{{ACS::InstanceName}}作为内置环境参数,需确保云助手Agent不低于以下版本:

      • Linux:2.2.3.344

      • Windows:2.1.3.344

    • {{ACS::InvokeId}}:命令执行ID。如需指定{{ACS::InvokeId}}作为内置环境参数,需确保云助手Agent不低于以下版本:

      • Linux:2.2.3.309

      • Windows:2.1.3.309

    • {{ACS::CommandId}}:命令ID。通过调用RunCommand接口执行命令时,如需指定{{ACS::CommandId}}作为内置环境参数,需确保云助手Agent不低于以下版本:

      • Linux:2.2.3.309

      • Windows:2.1.3.309

Timeout

Integer

您创建的命令在ECS实例中执行时的超时时间。

当因为某种原因无法运行您创建的命令时,会出现超时现象;超时后,会强制终止命令进程,即取消命令的PID。

默认值:60。

单位:秒。

Type

String

命令的类型。

取值:

  • RunBatScript:创建一个在Windows实例中运行的Bat脚本。

  • RunPowerShellScript:创建一个在Windows实例中运行的PowerShell脚本。

  • RunShellScript:创建一个在Linux实例中运行的Shell脚本。

Description

String

命令描述。

长度为1~512个字符。支持全字符集。

EnableParameter

Boolean

创建的命令是否使用自定义参数。

取值

  • true:使用自定义参数。

  • false(默认):不使用自定义参数。

Tags

List

实例的标签。最多支持添加20个标签。

更多信息,请参见Tags属性

ContentEncoding

String

命令内容(CommandContent)的编码方式。

取值范围:

  • PlainText:不编码,采用明文传输。

  • Base64(默认值):Base64编码。

说明

错填该取值会当作Base64处理。

ResourceGroupId

String

命令所属的资源组ID。

Tags语法

"Tags": [
  {
    "Key": String,
    "Value": String
  }
]

Tags属性

属性名称

类型

必须

允许更新

描述

约束

Key

String

标签键。

长度为1~128个字符,不能以aliyunacs:开头,不能包含http://https://

Value

String

标签值。

长度为0~128个字符,不能以aliyunacs:开头,不能包含http://https://

返回值

Fn::GetAtt

CommandId:命令ID。

说明

如果您只需要执行一次性命令,请参见ALIYUN::ECS::RunCommand

示例

YAML格式

ROSTemplateFormatVersion: '2015-09-01'
Parameters: {}
Resources:
  Command:
    Type: ALIYUN::ECS::Command
    Properties:
      CommandContent:
        Fn::Base64Encode: |
          #!/bin/bash
          echo "hello" >> /root/test.sh
      Type: RunShellScript
      Name:
        Ref: ALIYUN::StackName
Outputs:
  CommandId:
    Description: The id of command created.
    Value:
      Fn::GetAtt:
        - Command
        - CommandId

JSON格式

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
  },
  "Resources": {
    "Command": {
      "Type": "ALIYUN::ECS::Command",
      "Properties": {
        "CommandContent": {
          "Fn::Base64Encode": "#!/bin/bash\necho \"hello\" >> /root/test.sh\n"
        },
        "Type": "RunShellScript",
        "Name": {
          "Ref": "ALIYUN::StackName"
        }
      }
    }
  },
  "Outputs": {
    "CommandId": {
      "Description": "The id of command created.",
      "Value": {
        "Fn::GetAtt": [
          "Command",
          "CommandId"
        ]
      }
    }
  }
}