ALIYUN::ECS::Command

更新时间: 2023-11-02 13:56:22

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

语法

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

属性

属性名称

类型

必须

允许更新

描述

约束

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(默认):不使用自定义参数。

Tags

List

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

更多信息,请参见Tags属性

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"
            ]
          }
        }
      }
    }
阿里云首页 资源编排 相关技术圈