语法
{
"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实例中运行的目录。 | 默认值: |
CommandContent | String | 否 | 否 | 命令Base64编码后的内容。 | 命令Base64编码后的内容。 该参数的值必须使用Base64编码后传输,且脚本内容的大小在Base64编码之后不能超过18KB。 命令内容支持使用自定义参数形式,具体通过指定参数EnableParameter=true 启用自定义参数功能: 您可以指定内置环境参数作为自定义参数,执行命令时无需手动对参数赋值,云助手将为您自动替换为环境中对应的值。支持指定以下内置环境参数: {{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编码。
|
ResourceGroupId | String | 否 | 否 | 命令所属的资源组ID。 | 无 |
Tags语法
"Tags": [
{
"Key": String,
"Value": String
}
]
Tags属性
属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 |
Key | String | 是 | 否 | 标签键。 | 长度为1~128个字符,不能以aliyun 和acs: 开头,不能包含http:// 或https:// 。 |
Value | String | 否 | 否 | 标签值。 | 长度为0~128个字符,不能以aliyun 和acs: 开头,不能包含http:// 或https:// 。 |
返回值
Fn::GetAtt
CommandId:命令ID。
示例
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"
]
}
}
}
}