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 asC:\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 commandecho Jackis then run on the instance.
Try it now
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
ecs:CreateCommand |
create |
*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:
|
testDescription |
| Type |
string |
Yes |
The Base64-encoded content of the command.
|
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:
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:
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 |
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 |
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.