All Products
Search
Document Center

:CreateCommand

最終更新日:Nov 21, 2023

Creates a Cloud Assistant command.

Usage notes

  • You can create commands of the following types:
    • Batch commands (RunBatScript), applicable to Windows instances
    • PowerShell commands (RunPowerShellScript), applicable to Windows instances
    • Shell commands (RunShellScript), 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, Cloud Assistant Agent forcefully terminates the command process by canceling the process ID (PID) of the command.
    • For a one-time task, when the execution times out, the state of the command (InvokeRecordStatus) becomes Failed.
    • For a scheduled task, take note of the following items:
      • The timeout period takes effect on each execution.
      • When an execution times out, the state (InvokeRecordStatus) of the command becomes Failed.
      • The timeout of one execution does not affect the subsequent executions.
  • You can retain up to 500 to 10,000 Cloud Assistant commands in each region. You can perform operations that are described in the View and increase resource quotas topic or call the DescribeAccountAttribute operation to query resource quotas.
  • You can use WorkingDir to specify the execution directory of a Cloud Assistant command. For Linux instances, the default execution directory of Cloud Assistant commands is the home directory of the root user, which is /root. For Windows instances, the default execution directory of Cloud Assistant commands is the directory where the Cloud Assistant Agent process resides, such as C:\Windows\System32.
  • You can enable the custom parameter feature for a Cloud Assistant command by setting EnableParameter to true. When you set CommandContent, 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, if a command is echo {{name}}, the Parameters parameter can be used 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. As a result, the echo Jack command is actually run.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter

Type

Required

Example

Description

Action String Yes CreateCommand

The operation that you want to perform. Set the value to CreateCommand.

RegionId String Yes cn-hangzhou

The ID of the region in which to create the command. You can call the DescribeRegions operation to query the most recent region list.

Name String Yes testName

The name of the command. The name supports all character sets and can be up to 128 characters in length.

Description String No testDescription

The description of the command. The description supports all character sets and can be up to 512 characters in length.

Type String Yes RunShellScript

The type of the command. Valid values:

  • RunBatScript: batch command. Batch commands are applicable to Windows instances.
  • RunPowerShellScript: PowerShell command. PowerShell commands are applicable to Windows instances.
  • RunShellScript: shell command. Shell commands are applicable to Linux instances.
CommandContent String Yes ZWNobyAxMjM=

The Base64-encoded content of the command. Take note of the following items:

  • The value must be Base64-encoded and cannot exceed 18 KB in size.
  • Custom parameters can be added to the command. To enable the custom parameter feature, set EnableParameter to true.
    • Custom parameters are defined in the {{}} format. Within {{}}, the spaces and line feeds before and after the parameter names are ignored.
    • You can specify up to 20 custom parameters.
    • A custom parameter name can contain letters, digits, underscores (_), and hyphens (-). The name is case-insensitive. The ACS:: prefix cannot be used to specify non-built-in environment parameters.
    • Each custom parameter name cannot exceed 64 bytes in length.
  • You can specify built-in environment parameters as custom parameters. Then, when you run the command, these parameters are automatically specified by Cloud Assistant. You can specify the following built-in environment variables:
    • {{ACS::RegionId}}: the region ID.
    • {{ACS::AccountId}}: the UID of the Alibaba Cloud account.
    • {{ACS::InstanceId}}: the instance ID. When the command is run on multiple instances, if you want to specify {{ACS::InstanceId}} as a built-in environment variable, make sure that the Cloud Assistant Agent version is not earlier than the following ones:
      • Linux: 2.2.3.309
      • Windows: 2.1.3.309
    • {{ACS::InstanceName}}: the instance name. When the command is run on multiple instances, if you want to specify {{ACS::InstanceName}} as a built-in environment variable, make sure that the Cloud Assistant Agent version is not earlier than the following ones:
      • Linux: 2.2.3.344
      • Windows: 2.1.3.344
    • {{ACS::InvokeId}}: the task ID. If you want to specify {{ACS::InvokeId}} as a built-in environment variable, make sure that the Cloud Assistant Agent version is not earlier than the following ones:
      • Linux: 2.2.3.309
      • Windows: 2.1.3.309
    • {{ACS::CommandId}}: the ID of the command. When you call the RunCommand operation, if you want to specify {{ACS::CommandId}} as a built-in environment variable, make sure that the Cloud Assistant Agent version is not earlier than the following ones:
      • Linux: 2.2.3.309
      • Windows: 2.1.3.309
WorkingDir String No /home/user

The execution path of the command on ECS instances. The value can be up to 200 characters in length.

Default values:

  • For Linux instance, the default value is the home directory of the root user, which is the /root directory.
  • For Windows instances, the default value is the directory where the Cloud Assistant Agent process resides, such as C:\Windows\System32\.
Note If you set WorkingDir to a value other than default ones, make sure that the directory exists on the instance.
Timeout Long No 60

The 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.

EnableParameter Boolean No false

Specifies whether to use custom parameters in the command.

Default value: false.

ContentEncoding String No PlainText

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

  • PlainText: The command content is not encoded.
  • Base64: The command content is encoded in Base64.

Default value: Base64.

Note If the specified value of this parameter is invalid, Base64 is used by default.
ResourceGroupId String No rg-123******

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

Tag.N.Key String No TestKey

The key of tag N to add to the command. 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.

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

Tag.N.Value String No TestValue

The value of tag N to add to the command. 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://.

Response parameters

Parameter

Type

Example

Description

CommandId String c-7d2a745b412b4601b2d47f6a768d****

The ID of the command.

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

The ID of the request.

Examples

Sample requests

http(s)://ecs.aliyuncs.com/?Action=CreateCommand
&CommandContent=ZWNobyB7e25hbWV9fSA=
&Name=testName
&RegionId=cn-hangzhou
&Type=RunShellScript
&Description=testDescription
&WorkingDir=/home/user
&Timeout=60
&EnableParameter=true
&ContentEncoding=Base64
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<CreateCommandResponse>
    <CommandId>c-7d2a745b412b4601b2d47f6a768d****</CommandId>
    <RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3****</RequestId>
</CreateCommandResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "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. This operation cannot be performed in the specified region. Check whether the value of the 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 (_). Invalid custom parameter name. Each custom parameter name can contain only letters, digits, underscores (_), and hyphens (-).
400 CmdContent.DecodeError The CommandContent can not be base64 decoded. The command content cannot be decoded in Base64.
400 InvalidParameter.WorkingDir The specified parameter WorkingDir is not valid. Invalid WorkingDir value.
403 CmdContent.ExceedLimit The length of the command content exceeds the upper limit. The maximum length of the command content is exceeded.
403 CmdName.ExceedLimit The length of the command name exceeds the upper limit. The maximum length of the command name is exceeded.
403 CmdDesc.ExceedLimit The length of the command description exceeds the upper limit. The maximum length of the command description is exceeded.
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 is exceeded.
403 CmdParamCount.ExceedLimit The maximum number of custom parameters is exceeded. The maximum number of custom parameters is exceeded.
403 CmdParamName.ExceedLimit The maximum length of a parameter name is exceeded. The maximum length of a custom parameter name is exceeded.
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. You cannot perform this operation on a resource group that is being created or deleted.
404 InvalidCmdType.NotFound The specified command type does not exist. The specified command type is not found.
404 InvalidResourceGroup.NotFound The ResourceGroup provided does not exist in our records. The resource group is not found.
500 InternalError.Dispatch An error occurred when you dispatched the request. An error occurred while the request was being sent. Try again later.

For a list of error codes, see Service error codes.