ALIYUN::SWAS::RunCommand类型用于在轻量应用服务器上执行命令。
语法
{
"Type": "ALIYUN::SWAS::RunCommand",
"Properties": {
"CommandContent": String,
"InstanceId": String,
"Name": String,
"Type": String,
"ContentEncoding": String,
"EnableParameter": Boolean,
"Parameters": Map,
"Sync": Boolean,
"Timeout": Integer,
"WorkingDir": String,
"WorkingUser": String,
"WindowsPasswordName": String
}
}
属性
|
属性名称 |
类型 |
必须 |
允许更新 |
描述 |
约束 |
|
CommandContent |
String |
是 |
是 |
命令内容。 |
您需要注意:
|
|
InstanceId |
String |
是 |
否 |
轻量应用云服务器实例 ID。 |
无 |
|
Name |
String |
是 |
是 |
执行命令名称。 |
无 |
|
Type |
String |
是 |
是 |
命令的语言类型。 |
取值范围:
|
|
ContentEncoding |
String |
否 |
是 |
命令内容的编码模式。 |
取值: PlainText:命令内容未经过编码,以明文形式传输。(默认值) Base64:进行 base64 编码。 |
|
EnableParameter |
Boolean |
否 |
是 |
命令中是否包含自定义参数。 |
默认值:false。 |
|
Parameters |
Map |
否 |
是 |
命令中包含自定义参数时,执行命令时传入的自定义参数的键值对。 |
例如,命令内容为 自定义参数的个数范围为 0~20,且您需要注意:
默认值为空,表示取消设置该参数从而禁用自定义参数。 |
|
Sync |
Boolean |
否 |
否 |
是否同步运行命令。 |
无 |
|
Timeout |
Integer |
否 |
是 |
设置命令在服务器实例中的超时时间, |
单位为秒。 当执行命令的任务超时后,命令助手将强制终止任务进程。可设定超时时间取值范围为 10~86400 秒(24 小时)。 默认值:60。 |
|
WorkingDir |
String |
否 |
是 |
您可自定义命令的执行路径。 |
默认路径如下:
|
|
WorkingUser |
String |
否 |
是 |
您可以指定以某个轻量应用服务器实例中存在的用户执行命令, |
建议使用普通用户执行命令可降低安全风险。 默认值:
|
|
WindowsPasswordName |
String |
否 |
否 |
Windows 实例中执行命令的用户的密码名称。 |
当您希望以非默认用户(System)在 Windows 实例中执行命令时,需要同时传入 WorkingUser 和该参数。为降低密码泄露的风险,需要将密码明文托管在运维编排服务的参数仓库中,此处仅传入密码的名称。 |
返回值
Fn::GetAtt
-
InvokeResult:命令执行的结果。
-
InvokeId:命令执行 ID。
示例
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
CommandContent:
AssociationProperty: TextArea
Type: String
Description:
en: The plaintext content of the command to run.
Required: true
Type:
Type: String
Description:
en: |-
The language type of the O&M script. Valid values:
RunShellScript: shell scripts for Linux instances
RunBatScript: batch scripts for Windows instances
RunPowerShellScript: PowerShell scripts for Windows instances
AllowedValues:
- RunShellScript
- RunBatScript
- RunPowerShellScript
Required: true
InstanceId:
Type: String
Description:
en: The ID of the SWAS instance on which to run the command. The instance must be in 'Running' status.
Required: true
Name:
Type: String
Description:
en: The name of the command to run.
Required: true
Resources:
RunCommand:
Type: ALIYUN::SWAS::RunCommand
Properties:
CommandContent:
Ref: CommandContent
Type:
Ref: Type
InstanceId:
Ref: InstanceId
Name:
Ref: Name
Outputs:
InvokeResult:
Description: The result of the command execution.
Value:
Fn::GetAtt:
- RunCommand
- InvokeResult
InvokeId:
Description: The ID of the command execution.
Value:
Fn::GetAtt:
- RunCommand
- InvokeId
{
"ROSTemplateFormatVersion": "2015-09-01",
"Parameters": {
"CommandContent": {
"AssociationProperty": "TextArea",
"Type": "String",
"Description": {
"en": "The plaintext content of the command to run."
},
"Required": true
},
"Type": {
"Type": "String",
"Description": {
"en": "The language type of the O&M script. Valid values:\nRunShellScript: shell scripts for Linux instances\nRunBatScript: batch scripts for Windows instances\nRunPowerShellScript: PowerShell scripts for Windows instances"
},
"AllowedValues": [
"RunShellScript",
"RunBatScript",
"RunPowerShellScript"
],
"Required": true
},
"InstanceId": {
"Type": "String",
"Description": {
"en": "The ID of the SWAS instance on which to run the command. The instance must be in 'Running' status."
},
"Required": true
},
"Name": {
"Type": "String",
"Description": {
"en": "The name of the command to run."
},
"Required": true
}
},
"Resources": {
"RunCommand": {
"Type": "ALIYUN::SWAS::RunCommand",
"Properties": {
"CommandContent": {
"Ref": "CommandContent"
},
"Type": {
"Ref": "Type"
},
"InstanceId": {
"Ref": "InstanceId"
},
"Name": {
"Ref": "Name"
}
}
}
},
"Outputs": {
"InvokeResult": {
"Description": "The result of the command execution.",
"Value": {
"Fn::GetAtt": [
"RunCommand",
"InvokeResult"
]
}
},
"InvokeId": {
"Description": "The ID of the command execution.",
"Value": {
"Fn::GetAtt": [
"RunCommand",
"InvokeId"
]
}
}
}
}