All Products
Search
Document Center

Elastic Compute Service:CreateCommand

Last Updated:Jun 25, 2026

Creates a Cloud Assistant command of the Shell, PowerShell, or Bat script type.

Operation description

Operation description

  • You can create the following types of commands:
    • Bat scripts for Windows instances (RunBatScript).

    • PowerShell scripts for Windows instances (RunPowerShellScript).

    • Shell scripts for Linux instances (RunShellScript).

  • You can specify the Timeout parameter to set the maximum timeout period for a command to run on an ECS instance. If the command times out, Cloud Assistant Agent forcefully terminates the command process by canceling the PID of the command.
    • For a one-time execution, after the command times out, the execution status (InvokeRecordStatus) of the command on the specified ECS instance changes to Failed.

    • For a scheduled execution:
      • The timeout period takes effect for each execution record.

      • After a specific execution times out, the status (InvokeRecordStatus) of that execution record changes to Failed.

      • The timeout of a previous execution does not affect the next execution.

  • You can retain up to 500 to 50,000 Cloud Assistant commands in a region. You can also request a quota increase. For information about how to query and increase quotas, refer to Quota management.

  • You can specify the WorkingDir parameter to set the execution path of a command. For Linux instances, the default path is the home directory of the root user, which is /root. For Windows instances, the default path is the directory where the Cloud Assistant Agent process is located, such as C:\Windows\System32.

  • You can set EnableParameter to true to enable the custom parameter feature. When you set CommandContent, you can define custom parameters in the {{parameter}} format and pass in custom parameter key-value pairs when you run the command by calling InvokeCommand. For example, if you create the command echo {{name}} and pass in the key-value pair <name, Jack> through the Parameters parameter when you call InvokeCommand, the custom parameter is automatically replaced. The resulting command echo Jack is then run on the instance.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

ecs:CreateCommand

create

*Command

acs:ecs:{#regionId}:{#accountId}:command/*

None None

Request parameters

Parameter

Type

Required

Description

Example

RegionId

string

Yes

The region ID. You can call DescribeRegions to query the most recent region list.

cn-hangzhou

RegionId

string

Yes

The command name. All character sets are supported. The name cannot exceed 128 characters in length.

cn-hangzhou

Name

string

Yes

The command description. All character sets are supported. The description cannot exceed 512 characters in length.

testName

Description

string

No

The type of the command. Valid values:

  • RunBatScript: creates a Bat script to run on Windows instances.

  • RunPowerShellScript: creates a PowerShell script to run on Windows instances.

  • RunShellScript: creates a Shell script to run on Linux instances.

testDescription

Type

string

Yes

The Base64-encoded content of the command.

  • The value of this parameter must be Base64-encoded, and the script content cannot exceed 18 KB in size after Base64 encoding.

  • The command content supports custom parameters. To enable the custom parameter feature, set EnableParameter=true:

    • Custom parameters are defined by enclosing them in {{}}. Spaces and line breaks before and after the parameter name within {{}} are ignored.

    • The number of custom parameters cannot exceed 20.

    • Custom parameter names can contain letters (a-z, A-Z), digits (0-9), hyphens (-), and underscores (_). The acs:: prefix for specifying non-built-in environment parameters is not supported. Other characters are not supported. Parameter names are case-insensitive.

    • Each parameter name cannot exceed 64 bytes in length.

  • You can specify built-in environment parameters as custom parameters. When the command is run, Cloud Assistant automatically replaces them with the corresponding values from the environment without requiring manual assignment. The following built-in environment parameters are supported:

    • {{ACS::RegionId}}: the region ID.

    • {{ACS::AccountId}}: the UID of the Alibaba Cloud account.

    • {{ACS::InstanceId}}: the instance ID. When a command is sent to multiple instances and you want to use {{ACS::InstanceId}} as a built-in environment parameter, make sure that the Cloud Assistant Agent version is not earlier than:

      • Linux: 2.2.3.309

      • Windows: 2.1.3.309

    • {{ACS::InstanceName}}: the instance name. When a command is sent to multiple instances and you want to use {{ACS::InstanceName}} as a built-in environment parameter, make sure that the Cloud Assistant Agent version is not earlier than:

      • Linux: 2.2.3.344

      • Windows: 2.1.3.344

    • {{ACS::InvokeId}}: the command execution ID. To use {{ACS::InvokeId}} as a built-in environment parameter, make sure that the Cloud Assistant Agent version is not earlier than:

      • Linux: 2.2.3.309

      • Windows: 2.1.3.309

    • {{ACS::CommandId}}: the command ID. When you run a command by calling the RunCommand operation and want to use {{ACS::CommandId}} as a built-in environment parameter, make sure that the Cloud Assistant Agent version is not earlier than:

      • Linux: 2.2.3.309

      • Windows: 2.1.3.309.

RunShellScript

CommandContent

string

Yes

The directory where the command is run on the ECS instance. The value cannot exceed 200 characters in length.

Default value:

  • Linux instances: the home directory of the root user, which is /root.

  • Windows instances: the directory where the Cloud Assistant Agent process is located, such as C:\Windows\System32.

Note

If you set this parameter to a different directory, make sure that the directory exists on the instance.

ZWNobyAxMjM=

WorkingDir

string

No

The maximum timeout period for the command to run on the ECS instance. Unit: seconds. If the command cannot be run for any reason, a timeout occurs. After the timeout, the command process is forcefully terminated by canceling the PID of the command.

Default value: 60.

/home/user

Timeout

integer

No

Specifies whether the command uses custom parameters.

Default value: false.

60

EnableParameter

boolean

No

The encoding mode of the command content (CommandContent). Valid values:

  • PlainText: no encoding. The content is transmitted in plaintext.

  • Base64: Base64 encoding.

Default value: Base64.

Note

If an invalid value is specified, it is treated as Base64.

false

ContentEncoding

string

No

The client token that is used to ensure the idempotence of the request. You can use the client to generate the token, but make sure that the token is unique among different requests. ClientToken supports only ASCII characters and cannot exceed 64 characters in length. For more information, see How to ensure idempotence.

PlainText

ClientToken

string

No

The ID of the resource group to which the command belongs.

123e4567-e89b-12d3-a456-426655440000

ResourceGroupId

string

No

The bootstrap program for script execution. The value cannot exceed 1 KB in length.

rg-123******

Launcher

string

No

The list of tags.

python3 -u {{ACS::ScriptFileName|Ext(".py")}}

Tag

array<object>

No

The tags to add to the command.

object

No

Tag N to add to the command.

Key

string

No

The key of tag N. Valid values of N: 1 to 20. The tag key cannot be an empty string.

If a single tag is specified to query resources, up to 1,000 resources that have this tag added can be displayed in the response. If multiple tags are specified to query resources, up to 1,000 resources that have all these tags added can be displayed in the response. To query more than 1,000 resources that have specified tags, call ListTagResources operation.

The tag key can be up to 64 characters in length and cannot start with acs: or aliyun. It cannot contain http:// or https://.

TestKey

Value

string

No

The value of tag N. Valid values of N: 1 to 20. The tag value can be an empty string.

It can be up to 128 characters in length and cannot contain http:// or https://.

TestValue

Response elements

Element

Type

Description

Example

object

CommandId

string

The command ID.

c-7d2a745b412b4601b2d47f6a768d****

RequestId

string

The request ID.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3****

Examples

Success response

JSON format

{
  "CommandId": "c-7d2a745b412b4601b2d47f6a768d****",
  "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****"
}

Error codes

HTTP status code

Error code

Error message

Description

400 RegionId.ApiNotSupported The api is not supported in this region. The API operation cannot be called in the specified region. Check whether the specified RegionId parameter is valid.
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.
400 InvalidClientToken.Malformed The specified parameter clientToken is not valid.
500 InternalError.Dispatch An error occurred when you dispatched the request. An error occurred while the request is being sent. Try again later.
403 CmdContent.ExceedLimit The length of the command content exceeds the upper limit. The length of command content exceeds the upper limit.
403 CmdName.ExceedLimit The length of the command name exceeds the upper limit. The length of the command name exceeds the upper limit.
403 CmdDesc.ExceedLimit The length of the command description exceeds the upper limit. 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. The maximum number of Cloud Assistant commands in the current region has been exceeded.
403 CmdParamCount.ExceedLimit The maximum number of custom parameters is exceeded. The number of specified parameters exceeds the upper limit.
403 CmdParamName.ExceedLimit The maximum length of a parameter name is exceeded. The length of the custom parameter name exceeds the upper limit.
403 Operation.Forbidden The operation is not permitted. The operation is not supported.
403 InvalidStatus.ResourceGroup You cannot perform an operation on a resource group that is being created or deleted. Operation not allowed while resource group is being created or deleted.
403 InvalidParameterCharacter.CommandName The command Name contains illegal characters. The command Name contains illegal characters.
403 InvalidParameterCharacter.CommandDescription The command Description contains illegal characters. The command Description contains illegal characters.
403 InvalidParameterCharacter.CommandWorkingDir The command WorkingDir contains illegal characters. The command WorkingDir contains illegal characters.
403 InvalidLauncher.LengthLimitExceeded The length of the parameter Launcher exceeds the limit of 1 KB characters. The length of the argument Launcher exceeds the limit of 1 KB characters.
403 InvalidTimeout.ExceedLimit The specified parameter Timeout exceeds the upper limit.
403 IdempotentParameterMismatch The specified parameter has changed while using an already used clientToken.
403 IdempotentProcessing The previous idempotent request(s) is still processing. A previous idempotent request is being processed. Try again later.
404 InvalidCmdType.NotFound The specified command type does not exist.
404 InvalidRegionId.NotFound The RegionId provided does not exist in our records. Region information error
404 InvalidResourceGroup.NotFound The ResourceGroup provided does not exist in our records. The specified resource group does not exist.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.