You need to enable JavaScript to run this app.
文档中心
云服务器

云服务器

复制全文
下载 pdf
云助手
CreateCommand - 创建自定义命令
复制全文
下载 pdf
CreateCommand - 创建自定义命令
调用CreateCommand接口,新建一条自定义命令。​
使用说明​
可通过ParameterDefinitions.N.xxx参数在命令中配置自定义参数,使用规则如下:​
  • 参数 - N:表示自定义参数的序号,取值范围:1~60。​
  • 多个自定义参数之间用&分隔。​
调试​
API Explorer
您可以通过 API Explorer 在线发起调用,无需关注签名生成过程,快速获取调用结果。
​
请求参数​
下方仅列出该接口特有的请求参数和部分公共参数。更多信息请见公共参数。​
Action string 必选 示例值:CreateCommand​
要执行的操作,取值:CreateCommand。​
​
Version string 必选 示例值:2020-04-01​
API的版本,取值:2020-04-01。​
​
Tags.N.Key string[] 可选 示例值:Tags.1.Key=k1&Tags.2.Key=k2​
用户标签的标签键。​
  • 参数 - N:表示标签键的序号,取值范围:1~20。​
  • 多个标签键之间用&分隔。​
命名规则如下:​
  • 不能以volc:或sys:的任意大小写组合开头。​
  • 只能包含语言字符、数字、空格和英文符号“_”、“.”、“:”、“/”、“=”、“+”、“-”、“@”。​
  • 长度限制在1~128个字符之间。​
说明​
同一资源的标签键不允许重复。​
​
ProjectName string 可选 示例值:default​
资源所属项目,一个资源只能归属于一个项目。​
​
Tags.N.Value string[] 可选 示例值:Tags.1.Value=v1&Tags.2.Value=v2​
用户标签的标签值。​
  • 参数 - N:表示标签值的序号,取值范围:1~20。​
  • 多个标签值之间用&分隔。​
命名规则如下:​
  • 只能包含语言字符、数字、空格和英文符号“_”、“.”、“:”、“/”、“=”、“+”、“-”、“@”。​
  • 允许为空,长度限制在0~256个字符之间。​
说明​
如果传入该参数,则必须先传入Tags.N.Key。​
​
Name string 必选 示例值:updateAgent​
命令名称。需符合如下规则:​
  • 字符长度1~32。​
  • 不限制特殊字符。​
​
Description string 可选 示例值:This is a new command.​
命令描述,默认为空字符串。​
  • 字符长度0~256。​
  • 不限制特殊字符。​
​
Type string 必选 示例值:Shell​
命令的类型。取值:​
  • Shell:表示创建一个在Linux实例中运行的Shell脚本。​
  • Python:表示创建一个Python脚本。​
  • Bat:表示创建一个Bat脚本。​
  • PowerShell:表示创建一个PowerShell脚本。​
​
EnableParameter boolean 可选 示例值:false​
创建的命令是否使用自定义参数。取值:​
  • false:默认,表示不使用自定义参数。​
  • True:表示使用自定义参数。​
​
ParameterDefinitions.N.Name string[] 可选 示例值:ParameterDefinitions.1.Name=dir​
自定义参数名称,需要在脚本中通过{{Param}}定义 。命名规则:​
  • 单个参数名不能超过64字节。​
  • 遵循Shell变量命名规则,a-zA-Z0-9-_的组合。首个字符不能以数字开头。中间不能有空格,可以使用下划线。​
​
ParameterDefinitions.N.Type string[] 可选 示例值:ParameterDefinitions.1.Type=String​
自定义参数类型。取值:​
  • String:表示自定义参数类型为String(字符串)类型。​
  • Digit:表示自定义参数类型为Digit(数值)类型。​
​
ParameterDefinitions.N.Required boolean[] 可选 示例值:ParameterDefinitions.1.Required=true​
是否必填。取值:​
  • true:必填。​
  • false:非必填。​
​
ParameterDefinitions.N.DefaultValue string[] 可选 示例值:ParameterDefinitions.1.DefaultValue=ecs​
自定义参数默认值。​
​
ParameterDefinitions.N.MinLength integer[] 可选 示例值:ParameterDefinitions.1.MinLength=1​
自定义参数值(字符串)的最小长度。​
  • MinLength取值范围:1~1000。​
  • Type=String时必填,且Required参数为true时默认为1。​
  • 本参数值需小于MaxLength。​
​
ParameterDefinitions.N.MaxLength integer[] 可选 示例值:ParameterDefinitions.1.MaxLength=98​
自定义参数值(字符串)的最大长度。​
  • MaxLength取值范围:1~1000。​
  • Type=String时必填,且Required参数为true时默认为1000。​
  • 本参数值需大于MinLength。​
​
ParameterDefinitions.N.MinValue string[] 可选 示例值:ParameterDefinitions.1.MinValue=1​
自定义参数值(数值)的最小值。​
  • MinValue取值范围:-1000000~1000000。​
  • Type=Digit时必填,且Required参数为true时默认为-1000000。​
  • 本参数值需小于MaxValue​
​
ParameterDefinitions.N.MaxValue string[] 可选 示例值:ParameterDefinitions.1.MaxValue=100​
自定义参数值(数值)的最大值。​
  • MaxValue取值范围:-1000000~1000000。​
  • Type=Digit时必填,且Required参数为true时默认为1000000。​
  • 本参数值需小于MinValue。​
​
ParameterDefinitions.N.DecimalPrecision integer[] 可选 示例值:ParameterDefinitions.1.DecimalPrecision=4​
自定义参数值(数值)允许的小数点后位数。​
  • DecimalPrecision取值范围:0~10。​
  • Type=Digit时必填,且Required参数为true时默认为0。​
​
CommandContent string 必选 示例值:IyEvYmluL2Jhc2gKZWNobyAib3BlcmF0aW9uIHN1Y2Nlc3MhIg==​
命令内容。​
  • 请根据ContentEncoding参数传入相应命令内容。​
  • 请确保在编码前的脚本首行,按如下规范指定了脚本解释器。规则如下:​
  • Shell脚本:首行需为#!/bin/bash。​
  • Python脚本:首行需为#!/usr/bin/python。​
  • 命令内容不能超过16KB。​
  • EnableParameter=true时,命令内容支持使用自定义参数。规则如下:​
  • 自定义参数用{{}}包含的方式定义。​
  • 在{{}}内参数名前后的空格以及换行符会被忽略。​
​
WorkingDir string 可选 示例值:/home​
创建的命令在ECS实例中运行的目录。Linux实例默认为/home。​
​
Username string 可选 示例值:root​
执行命令时的用户名。​
​
Timeout integer 可选 示例值:60​
创建的命令在ECS实例中执行时最大的超时时间,单位为秒。​
  • 取值范围:30~86400。​
  • 默认值:60。​
​
ContentEncoding string 可选 示例值:Base64​
命令内容是否经过Base64编码处理。取值:​
  • Base64(默认):经过Base64编码处理。​
  • PlainText: 未进行编码处理。​
​
​
​
返回参数​
下方仅列出本接口特有的返回参数。更多信息请参见返回结构。​
CommandId string 示例值:cmd-ycgpkuavyrm0tq****​
自定义命令ID。​
​
​
​
请求示例​
​
GET /?Action=CreateCommand&Version=2020-04-01&Name=demo&Description=123&Type=Shell&EnableParameter=true&ParameterDefinitions.1.Name=a&ParameterDefinitions.1.Description=desc&ParameterDefinitions.1.Required=true&ParameterDefinitions.1.Required=true&ParameterDefinitions.1.DefaultValue=123&ParameterDefinitions.1.Type=String&ParameterDefinitions.1.MaxLength=1000&ParameterDefinitions.1.MinLength=1&CommandContent=IyEvYmluL2Jhc2gKZWNobyB7e2F9fQ==&WorkingDir=/home&Username=root&Timeout=60​
Host: ecs.cn-beijing.volcengineapi.com​
Region: cn-beijing​
Service: ecs​
​
返回示例​
​
{​
"ResponseMetadata":{​
"RequestId":"2023082515303301022514515207C4****",​
"Action":"CreateCommand",​
"Version":"2020-04-01",​
"Service":"ecs",​
"Region":"cn-beijing"​
},​
"Result":{​
"CommandId":"cmd-shhrh****"​
}​
}​
​
错误码​
下表为您列举了该接口与业务逻辑相关的错误码。公共错误码请参见公共错误码文档。​
​
状态码​
错误码​
错误信息​
说明​
400​
InvalidEnableParameter.Malformed​
The specified EnableParameter is malformed.​
指定的是否启用参数不合法。​
400​
InvalidTagKey.Malformed​
The specified TagKey is malformed.​
指定的标签键不合法。​
400​
InvalidTagValue.Malformed​
The specified TagValue is malformed.​
指定的标签值不合法。​
400​
LimitExceeded.MaximumDescription​
The specified Description exceeds the limit.​
指定的命令描述长度超出限制。​
400​
LimitExceeded.MaximumName​
The specified Name exceeds the limit.​
指定的命令名称长度超出限制。​
400​
MissingParameter.Name​
The required parameter Name is not supplied.​
命令名称不能为空。​
400​
InvalidType.Malformed​
The specified Type is malformed.​
指定的命令类型不合法。​
400​
MissingParameter.AccountId​
The required parameter AccountId is not supplied.​
用户ID不能为空。​
400​
LimitExceeded.MaximumTimeout​
The specified timeout exceeds the limit.​
指定的超时时间(s)超出限制。​
400​
LimitExceeded.Tags​
You've reached the limit on the number of Tags that you can create.​
已达到可创建的标签数量上限。​
400​
MissingParameter.Type​
The required parameter Type is not supplied.​
命令类型不能为空。​
400​
QuotaExceeded.MaximumCommands​
You've reached the limit on the number of Commands that you can create, please submit ticket to request an increase in quota.​
自定义命令配额不足,请提工单申请提高配额。​
400​
MissingParameter.CommandContent​
The required parameter CommandContent is not supplied.​
命令内容不能为空。​
400​
InvalidParameterDefinitions.Malformed​
The specified ParameterDefinitions is malformed.​
指定的参数定义不合法。​
400​
InvalidProjects.ListFailed​
Fail to list projects.​
获取项目失败。​
400​
LimitExceeded.MaximumParameterDefinitionName​
The specified ParameterDefinitionName exceeds the limit.​
指定的自定义参数名长度超出限制。​
400​
InvalidParameterDefinitionType.Malformed​
The specified ParameterDefinition Type is malformed.​
自定义参数类型不合法。​
400​
MissingParameter.ParameterDefinitionName​
The required parameter ParameterDefinitionName is not supplied.​
自定义参数名不能为空。​
400​
InvalidParameterDefinitionName.Malformed​
The specified ParameterDefinition Name is malformed. The name can contain only lowercase letters (a to z), uppercase letters (A to Z), numbers (0 to 9), and underscores (_).​
自定义参数名格式错误:仅支持a-zA-Z0-9_的组合,首个字符不能以数字开头。​
400​
LimitExceeded.MaximumParameterDefinitions​
The specified ParameterDefinitions exceeds the limit.​
指定的自定义参数定义个数超出限制。​
400​
InvalidBase64Content.Malformed​
The specified Base64 Content is malformed.​
指定的Base64内容不合法。​
400​
MissingParameter.ParameterDefinitions​
The required parameter ParameterDefinitions is not supplied.​
参数定义不能为空。​
400​
LimitExceeded.MaximumCommandContent​
The specified CommandContent exceeds the limit.​
指定的命令内容长度超出限制。​
404​
MissingParameter.Tags​
The required parameter Tags are empty.​
标签参数不能为空。​
404​
InvalidProject.NotFound​
The specified Project does not exist.​
指定的项目不存在。​
404​
InvalidParameterDefinitions.NotFound​
The specified ParameterDefinitions does not exist.​
指定的自定义参数未定义。​
409​
InvalidTagKey.Conflict​
The specified TagKey already exists.​
指定的标签键已存在。​
409​
InvalidParameterDefinitions.Conflict​
The specified ParameterDefinition already exists.​
指定的自定义参数已存在。​
​
​
最近更新时间:2026.10.09 15:23:54
这个页面对您有帮助吗?
有用
有用
无用
无用