CreateCommand_云服务器 ECS_API文档

插件下载了解更多
VS Code 插件
安装插件之前,确保已安装 VS Code安装插件之前,确保已安装 VS Code
Alibaba Cloud Developer Toolkit is a collection of extensions that can help access Alibaba Cloud services in Visual Studio Code.
JetBrains 插件
安装插件之前,确保已安装 JetBrains IDE安装插件之前,确保已安装 JetBrains IDE
The Alibaba Cloud Developer Toolkit for JetBrains makes it easier to access Alibaba Cloud services.

接口说明

  • 您可以创建以下类型的命令:
    • Windows 实例适用的 Bat 脚本(RunBatScript)。
    • Windows 实例适用的 PowerShell 脚本(RunPowerShellScript)。
    • Linux 实例适用的 Shell 脚本(RunShellScript)。
  • 您可以通过指定参数 Timeout 为命令设置在 ECS 实例中执行时最大的超时时间,命令执行超时后,云助手 Agent会强制终止命令进程,即取消命令的 PID。
    • 对于单次执行,超时后,该命令针对指定的 ECS 实例的执行状态( InvokeRecordStatus )变为执行失败(Failed)。
    • 对于定时执行:
      • 定时执行的超时时间对每一次执行记录均有效。
      • 某次执行超时后,该次执行记录的状态( InvokeRecordStatus )变为执行失败(Failed)。
      • 上次执行超时与否不影响下一次执行。
  • 在一个地域下,您最多可以保有 500~50,000 条云助手命令,您也可以申请提升配额,关于如何查询及提升配额,请参见配额管理
  • 您可以通过指定参数 WorkingDir 为命令指定执行路径。对于 Linux 实例,默认在管理员 root 用户的 home 目录下,具体为/root目录。对于 Windows 实例,默认在云助手 Agent 进程所在目录,例如:C:\Windows\System32
  • 您可以通过指定参数 EnableParameter=true 启用自定义参数功能。在设置 CommandContent 时可以通过{{parameter}}的形式表示自定义参数,并在运行命令( InvokeCommand )时,传入自定义参数键值对。例如,您在创建命令时,创建了echo {{name}}命令,在 InvokeCommand 时,通过 Parameters 参数传入键值对<name, Jack>。则自定义参数将自动替换命令,您会得到一条新的命令,并在实例中执行echo Jack

流控信息

请求速率为1000/60(s)。更多流控信息,请前往配额中心查看

授权信息

如下是此API对应的授权信息,用于RAM权限策略语句的Action元素中,为RAM用户或RAM角色授予调用此API的权限。请通过 RAM 访问控制设置,使用方法可参考访问控制帮助文档

具体说明如下:展开详情

操作访问级别资源类型条件关键字关联操作
ecs:CreateCommand
Create
Command
acs:ecs:{#regionId}:{#accountId}:command/*

请求参数

字段名称字段详情
RegionIdstring

地域 ID。您可以调用 DescribeRegions 查看最新的阿里云地域列表。

示例值:cn-hangzhou参考取值来源:
    DescribeRegions
Namestring

命令名称,支持全字符集。长度不得超过 128 个字符。

示例值:testName
Descriptionstring

命令描述,支持全字符集。长度不得超过 512 个字符。

示例值:testDescription
Typestring

命令的类型。取值范围: 展开详情

示例值:RunShellScript
CommandContentstring

命令 Base64 编码后的内容。展开详情

示例值:ZWNobyAxMjM=
WorkingDirstring

您创建的命令在 ECS 实例中运行的目录。长度不得超过 200 个字符。展开详情

示例值:/home/user
Timeoutinteger<int64>

您创建的命令在 ECS 实例中执行时最大的超时时间,单位为秒。当因为某种原因无法运行您创建的命令时,会出现超时现象。超时后,会强制终止命令进程,即取消命令的 PID。展开详情

注意 该字段类型为 Long,在序列化/反序列化的过程中可能导致精度丢失,请注意数值不得大于 9007199254740991。
示例值:60
EnableParameterboolean

创建的命令是否使用自定义参数。展开详情

示例值:false
ContentEncodingstring

命令内容(CommandContent)的编码方式。取值范围:展开详情

示例值:PlainText
ResourceGroupIdstring

命令所属的资源组 ID。

示例值:rg-123******参考取值来源:
    DescribeSecurityGroups
Launcherstring

脚本执行的引导程序。长度不能超过 1 KB。

示例值:python3 -u {{ACS::ScriptFileName|Ext(".py")}}
Tagarray<object>

标签列表。

子级条数 <= 21

返回参数

字段名称字段详情
CommandIdstring

命令 ID。

示例值:c-7d2a745b412b4601b2d47f6a768d****
RequestIdstring

请求 ID。

示例值:473469C7-AA6F-4DC5-B3DB-A3DC0DE3****

返回示例

错误码

全局错误码
HTTP 状态码错误码错误信息操作
400
RegionId.ApiNotSupported
The api is not supported in this region.诊断
400
CmdParam.EmptyKey
You must specify the parameter names.诊断
400
CmdParam.InvalidParamName
Invalid parameter name. The name can contain only lowercase letters (a to z), uppercase letters (A to Z), numbers (0 to 9), hyphens (-), and underscores (_).诊断
400
CmdContent.DecodeError
The CommandContent can not be base64 decoded.诊断
400
InvalidParameter.WorkingDir
The specified parameter WorkingDir is not valid.诊断
403
CmdContent.ExceedLimit
The length of the command content exceeds the upper limit.诊断
403
CmdName.ExceedLimit
The length of the command name exceeds the upper limit.诊断
403
CmdDesc.ExceedLimit
The length of the command description exceeds the upper limit.诊断
403
CmdCount.ExceedQuota
The total number of commands in the current region exceeds the quota.诊断
403
CmdParamCount.ExceedLimit
The maximum number of custom parameters is exceeded.诊断
403
CmdParamName.ExceedLimit
The maximum length of a parameter name is exceeded.诊断
403
Operation.Forbidden
The operation is not permitted.诊断
403
InvalidStatus.ResourceGroup
You cannot perform an operation on a resource group that is being created or deleted.诊断
403
InvalidParameterCharacter.CommandName
The command Name contains illegal characters.诊断
403
InvalidParameterCharacter.CommandDescription
The command Description contains illegal characters.诊断
403
InvalidParameterCharacter.CommandWorkingDir
The command WorkingDir contains illegal characters.诊断
403
InvalidLauncher.LengthLimitExceeded
The length of the parameter Launcher exceeds the limit of 1 KB characters.诊断
404
InvalidCmdType.NotFound
The specified command type does not exist.诊断
404
InvalidRegionId.NotFound
The RegionId provided does not exist in our records.诊断
404
InvalidResourceGroup.NotFound
The ResourceGroup provided does not exist in our records.诊断
500
InternalError.Dispatch
An error occurred when you dispatched the request.诊断

变更历史

变更时间变更内容概要操作
2024-10-21
变更错误码403
新增请求参数Launcher
2024-05-11
变更错误码403
2023-10-24
变更错误码403
变更错误码404
新增请求参数ResourceGroupId
2023-05-12
变更错误码400
变更错误码403
变更错误码404
  • 1
  • 2
  • 10 条/页

相关示例