Creates a Cloud Assistant command.
Operation description
-
You can create commands of the following types:
- RunBatScript: batch commands. These commands are applicable to Windows instances.
- RunPowerShellScript: PowerShell commands. These commands are applicable to Windows instances.
- RunShellScript: shell commands. These commands are applicable to Linux instances.
-
You can specify the TimeOut parameter to set the maximum timeout period for executions of a command on Elastic Compute Service (ECS) instances. If an execution times out, the Cloud Assistant client forcefully terminates the command process by canceling the process ID (PID) of the command. For more information, see Install the Cloud Assistant client.
-
When the one-time execution of a command times out, the execution state ( InvokeRecordStatus ) of the command becomes Failed.
-
For a scheduled task, take note of the following items:
- The timeout period takes effect on each execution of the command.
- When a scheduled execution of a command times out, the execution state ( InvokeRecordStatus ) of the command becomes Failed.
- The timeout of one execution does not affect the subsequent executions of the command.
-
-
You can retain up to 500 to 10,000 Cloud Assistant commands in each region.
-
You can use the WorkingDir parameter to specify the execution directory of a Cloud Assistant command. For Linux instances, the default execution directory of a command is the home directory of the root user, which is
/root
. For Windows instances, the default execution directory of a command is the directory where the Cloud Assistant client process resides, such asC:\Windows\System32
. -
You can enable the custom parameter feature for a Cloud Assistant command by setting EnableParameter to true when you create the command. When you configure the CommandContent parameter, you can define custom parameters in the {{parameter}} format. Then, when the InvokeCommand operation is called, the key-value pairs of custom parameters are passed in. For example, assume that the command content is
echo {{name}}
. You can use the Parameters parameter to pass in the<name, Jack>
key-value pair when the InvokeCommand operation is called. The name key of the custom parameter is automatically replaced by the paired Jack value to generate a new command. Therefore, theecho Jack
command is actually run.
Debugging
Authorization information
Request parameters
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
RegionId | string | Yes | The ID of the region in which to create the command. You can call the DescribeRegions operation to query the most recent region list. | cn-hangzhou |
Name | string | Yes | The name of the command. The name supports all character sets and can be up to 128 characters in length. | testName |
Description | string | No | The description of the command. The description supports all character sets and can be up to 512 characters in length. | testDescription |
Type | string | Yes | The command type. Valid values:
| RunShellScript |
CommandContent | string | Yes | The Base64-encoded content of the command.
| ZWNobyAxMjM= |
WorkingDir | string | No | The working directory of the command on the instance. Default value:
| /root/ |
Timeout | long | No | he maximum timeout period for the command execution on the instance. Unit: seconds. When a command that you created cannot be run, the command times out. When a command execution times out, Cloud Assistant Agent forcefully terminates the command process by canceling the PID. Default value: 60. | 60 |
EnableParameter | boolean | No | Specifies whether to use custom parameters in the command. Default value: false. | false |
ContentEncoding | string | No | The encoding mode of the command content (CommandContent). Valid values:
Default value: Base64. Note
If the specified value of this parameter is invalid, Base64 is used by default.
| PlainText |
ResourceGroupId | string | No | The ID of the resource group to which to assign the command. | rg-123****** |
Tag | object [] | No | The tags 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 parameters
Examples
Sample success responses
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. | Some required parameters are not specified. |
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 (_). | The custom parameter name is invalid. A custom parameter name can contain only letters, digits, underscores (_), and hyphens (-). |
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. | 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. |
404 | InvalidCmdType.NotFound | The specified command type does not exist. | - |
404 | InvalidRegionId.NotFound | The RegionId provided does not exist in our records. | The RegionId provided does not exist |
404 | InvalidResourceGroup.NotFound | The ResourceGroup provided does not exist in our records. | The specified resource group does not exist. |
500 | InternalError.Dispatch | An error occurred when you dispatched the request. | An error occurred while the request is being sent. Try again later. |
For a list of error codes, visit the Service error codes.
Change history
Change time | Summary of changes | Operation | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2023-10-24 | The Error code has changed. The request parameters of the API has changed | see changesets | ||||||||||||||
| ||||||||||||||||
2023-05-12 | The Error code has changed | see changesets | ||||||||||||||
| ||||||||||||||||
2022-02-25 | The Error code has changed | see changesets | ||||||||||||||
|