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

语法

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

属性

属性名称 类型 必须 允许更新 描述 约束
Name String 命令名称。 长度为1~128个字符。支持全字符集。
WorkingDir String 您创建的命令在ECS实例中运行的目录。 默认值:
  • Linux实例:管理员root用户的home目录下,取值为:/root
  • Windows实例:云助手客户端进程所在目录,例如C:\Windows\System32
CommandContent String 命令Base64编码后的内容。 该参数的值必须使用Base64编码后传输,且脚本内容的大小在Base64编码之后不能超过16KB。
命令内容支持使用自定义参数形式,具体通过指定参数EnableParameter=true启用自定义参数功能:
  • 自定义参数用两个大括号({{}})包含的方式定义,在两个大括号({{}})内参数名前后的空格以及换行符会被忽略。
  • 自定义参数个数不能超过20个。
  • 自定义参数名可包含英文字母和数字,参数名不区分大小写。
  • 单个参数名不能超过64个字符。
Timeout Integer 您创建的命令在ECS实例中执行时的超时时间。

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

默认值:60

单位:秒。
Type String 命令的类型。 取值:
  • RunBatScript:创建一个在Windows 实例中运行的Bat脚本。
  • RunPowerShellScript:创建一个在Windows实例中运行的PowerShell脚本。
  • RunShellScript:创建一个在Linux实例中运行的Shell脚本。
Description String 命令描述。 长度为1~512个字符。支持全字符集。
EnableParameter Boolean 创建的命令是否使用自定义参数。 取值
  • true
  • false(默认)

返回值

Fn::GetAtt

CommandId:命令ID。

示例

JSON格式

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "WorkingDir": {
      "Type": "String",
      "Description": "The path where command will be executed in the instance."
    },
    "CommandContent": {
      "Type": "String",
      "Description": "The content of command. Content requires base64 encoding. Maximum size support 16KB."
    },
    "Type": {
      "Type": "String",
      "Description": "The type of command."
    },
    "Description": {
      "Type": "String",
      "Description": "The description of command."
    },
    "Timeout": {
      "Type": "Number",
      "Description": "Total timeout when the command is executed in the instance. Input the time unit as second. Default is 60s."
    },
    "EnableParameter": {
      "Type": "Boolean",
      "Description": "Specifies whether the script contains custom parameters.\nDefault value: false",
      "AllowedValues": [
        true,
        false
      ]
    },
    "Name": {
      "Type": "String",
      "Description": "The name of command."
    }
  },
  "Resources": {
    "Command": {
      "Type": "ALIYUN::ECS::Command",
      "Properties": {
        "WorkingDir": {
          "Ref": "WorkingDir"
        },
        "CommandContent": {
          "Ref": "CommandContent"
        },
        "Type": {
          "Ref": "Type"
        },
        "Description": {
          "Ref": "Description"
        },
        "Timeout": {
          "Ref": "Timeout"
        },
        "EnableParameter": {
          "Ref": "EnableParameter"
        },
        "Name": {
          "Ref": "Name"
        }
      }
    }
  },
  "Outputs": {
    "CommandId": {
      "Description": "The id of command created.",
      "Value": {
        "Fn::GetAtt": [
          "Command",
          "CommandId"
        ]
      }
    }
  }
}

YAML格式

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  WorkingDir:
    Type: String
    Description: The path where command will be executed in the instance.
  CommandContent:
    Type: String
    Description: >-
      The content of command. Content requires base64 encoding. Maximum size
      support 16KB.
  Type:
    Type: String
    Description: The type of command.
  Description:
    Type: String
    Description: The description of command.
  Timeout:
    Type: Number
    Description: >-
      Total timeout when the command is executed in the instance. Input the time
      unit as second. Default is 60s.
  EnableParameter:
    Type: Boolean
    Description: |-
      Specifies whether the script contains custom parameters.
      Default value: false
    AllowedValues:
      - true
      - false
  Name:
    Type: String
    Description: The name of command.
Resources:
  Command:
    Type: 'ALIYUN::ECS::Command'
    Properties:
      WorkingDir:
        Ref: WorkingDir
      CommandContent:
        Ref: CommandContent
      Type:
        Ref: Type
      Description:
        Ref: Description
      Timeout:
        Ref: Timeout
      EnableParameter:
        Ref: EnableParameter
      Name:
        Ref: Name
Outputs:
  CommandId:
    Description: The id of command created.
    Value:
      'Fn::GetAtt':
        - Command
        - CommandId