Creates and runs a Cloud Assistant command, such as a Shell, PowerShell, or Bat script, on one or more ECS instances. This operation also supports scheduled execution, custom parameters, and execution in containers.
Operation description
This is an asynchronous API. After a successful request, you can call DescribeInvocations or DescribeInvocationResults with the returned command ID or invocation ID to query the execution results.
Usage notes
-
The target instance must be in the
Runningstate. You can call DescribeInstances to query the instance status. -
The Cloud Assistant Agent must be pre-installed on the target instance. Otherwise, call InstallCloudAssistant to install it and then call DescribeCloudAssistantStatus to query its installation status.
NoteBy default, the Cloud Assistant Agent is pre-installed on ECS instances that are created from public images after December 1, 2017.
-
When running PowerShell commands, make sure the PowerShell module is configured on the instance's Windows operating system.
Precautions
-
You can retain 500 to 50,000 Cloud Assistant commands in a single region. To request a higher quota, see Quota Management.
-
To use new features for scheduled tasks, such as running tasks at fixed intervals, running a task only once at a specified time, or specifying a year or time zone for cron expression-based tasks, the Cloud Assistant Agent must be one of the following versions or later. If the
ClientNeedUpgradeerror code is returned, see Upgrade or stop upgrading Cloud Assistant Agent to update the agent to the latest version.- Linux: 2.2.3.282 - Windows: 2.1.3.282 -
When you run a scheduled task based on a cron expression and specify a time zone, the task runs in the specified time zone. If you do not specify a time zone, the task runs in the system time zone of the ECS instance, and the execution time depends on the instance's system clock. Ensure that the time and time zone of your ECS instance are set as expected. For more information about time zones, see Set the time zone and NTP service for a Linux instance or Set the NTP service for a Windows instance.
Recommendations
-
Timeout settings: You can specify the
Timeoutparameter to set the maximum execution timeout for a command on an ECS instance. If the command execution times out, the Cloud Assistant Agent forcibly terminates the process.-
If a one-time execution times out, its execution status (InvokeRecordStatus) becomes Failed.
-
For a scheduled task, the timeout period applies to each execution. A timeout in one execution does not affect the next. If an execution times out, its execution status (InvokeRecordStatus) becomes Failed.
-
-
Execution failures: A command can fail due to an abnormal instance state, network problems, or an unresponsive Cloud Assistant Agent. In these cases, no execution information is generated. For more information, see Common errors and suggestions for fixing execution failures.
-
Custom parameters: To use custom parameters, set
EnableParametertotrue. You can then define parameters inCommandContentusing the{{parameter}}format and pass their corresponding key-value pairs when you run the command.
Try it now
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
ecs:RunCommand |
update |
*Instance
|
|
None |
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| RegionId |
string |
Yes |
The ID of the region. You can call the DescribeRegions operation to query the latest Alibaba Cloud regions. |
cn-hangzhou |
| ResourceGroupId |
string |
No |
The ID of the resource group for the command execution. When you specify this parameter, the following rules apply:
|
rg-bp67acfmxazb4p**** |
| RegionId |
string |
Yes |
The ID of the region. You can call the DescribeRegions operation to query the latest Alibaba Cloud regions. |
cn-hangzhou |
| Name |
string |
No |
The name of the command. It can be up to 128 characters long and supports all character sets. |
testName |
| Description |
string |
No |
The description of the command. It can be up to 512 characters long and supports all character sets. |
testDescription |
| Type |
string |
Yes |
The type of the command. Valid values:
|
RunShellScript |
| CommandContent |
string |
Yes |
The command content, which can be in plaintext or Base64-encoded. Note the following:
|
ZWNobyAxMjM= |
| WorkingDir |
string |
No |
The working directory for the command on the instance. The path can be up to 200 characters long. Default values:
|
/home/user |
| Timeout |
integer |
No |
The command execution timeout, in seconds. A timeout forcibly terminates the command process if the command fails to run due to exceptions, such as a process conflict, a missing module, or a disabled Cloud Assistant Agent. Default value: 60. |
3600 |
| EnableParameter |
boolean |
No |
Specifies whether to use custom parameters in the command. Default value: false. |
false |
| RepeatMode |
string |
No |
The execution mode of the command. Valid values:
Default value:
Notes:
|
Once |
| Timed |
boolean |
No |
Note
This parameter is deprecated and no longer has any effect. |
true |
| Frequency |
string |
No |
The schedule for the command. You can specify a rate expression, an at expression for one-time execution, or a cron expression.
|
0 */20 * * * ? |
| Parameters |
object |
No |
The key-value pairs for custom parameters. For example, if You can specify 0 to 10 key-value pairs. Note the following:
By default, this parameter is empty, which indicates that no custom parameters are used. |
{"name":"Jack", "accessKey":"LTAI*************"} |
| KeepCommand |
boolean |
No |
Specifies whether to save the command after it is run. Valid values:
Default value: false. |
false |
| ContentEncoding |
string |
No |
The encoding mode of the command content (
Default value: |
Base64 |
| Username |
string |
No |
The name of the user that runs the command on the ECS instance. The name can be up to 255 characters in length.
You can specify another existing user on the instance to run the command. Running Cloud Assistant commands as a standard user is more secure. For more information, see Run Cloud Assistant commands as a standard user. |
test |
| WindowsPasswordName |
string |
No |
The name of the password of the user that runs the command on a Windows instance. The name can be up to 255 characters in length. To run a command as a non-default user on a Windows instance, you must specify both Note
You do not need to specify this parameter when you run a command as the |
axtSecretPassword |
| InstanceId |
array |
No |
The IDs of the ECS instances on which to run the command. You can specify from 1 to 100 instance IDs. If any specified instance does not meet the execution requirements, the entire operation fails. You can apply for a quota increase in Quota Center. The quota is named Maximum number of instances supported per command execution. |
i-bp185dy2o3o6neg**** |
|
string |
No |
The ID of an ECS instance. |
i-bp185dy2o3o6neg**** |
|
| Tag |
array<object> |
No |
An array of tag pairs. The array can contain 0 to 20 tags. |
|
|
object |
No |
A tag pair. |
||
| Value |
string |
No |
The tag value for the command execution. The value can be an empty string. The value can be up to 128 characters long and cannot contain |
TestValue |
| Key |
string |
No |
The tag key for the command execution. The key cannot be an empty string. The key can be up to 64 characters long and cannot start with The value can be up to 64 characters long and cannot start with |
TestKey |
| ContainerId |
string |
No |
The ID of the container. The ID must be a 64-bit hexadecimal string. You can add the Notes:
Note
In Linux containers, you can run only Shell scripts. You cannot use commands such as |
ab141ddfbacfe02d9dbc25966ed971536124527097398d419a6746873fea**** |
| ContainerName |
string |
No |
The name of the container. Notes:
Note
In Linux containers, you can run only Shell scripts. You cannot use commands such as |
test-container |
| ClientToken |
string |
No |
A client-generated token that is used to ensure the idempotence of the request. You must make sure that the token is unique among different requests. The |
123e4567-e89b-12d3-a456-426655440000 |
| OssOutputDelivery |
string |
No |
The OSS delivery configuration for the command output.
|
oss://testBucket/testPrefix |
| ResourceTag |
array<object> |
No |
Tags used to filter instances for command execution. This allows you to run the command on all instances with matching tags, as an alternative to specifying instance IDs. The array can contain 0 to 20 tags. |
|
|
object |
No |
A tag that is used to filter instances. You can run a command on multiple instances that have the same tags without specifying their instance IDs. |
||
| Value |
string |
No |
The tag value that is used to filter instances. Notes:
|
TestValue |
| Key |
string |
No |
The tag key that is used to filter instances. Notes:
|
TestKey |
| TerminationMode |
string |
No |
The mode for stopping the task when it is manually stopped or times out. Valid values:
|
ProcessTree |
| Launcher |
string |
No |
The launcher that is used to run the script. The value can be up to 1 KB in length. |
python3 -u {{ACS::ScriptFileName|Ext(".py")}} |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
|||
| RequestId |
string |
The ID of the request. |
473469C7-AA6F-4DC5-B3DB-A3DC0DE3**** |
| CommandId |
string |
The ID of the command. |
c-7d2a745b412b4601b2d47f6a768d**** |
| InvokeId |
string |
The ID of the command execution. |
t-7d2a745b412b4601b2d47f6a768d**** |
Examples
Success response
JSON format
{
"RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****",
"CommandId": "c-7d2a745b412b4601b2d47f6a768d****",
"InvokeId": "t-7d2a745b412b4601b2d47f6a768d****"
}
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 | ResourceBusy.SlrCreation | The ServiceLinkedRole is still being created or has not taken effect yet. Please try again later. | |
| 400 | MissingParam.InstanceId | The parameter instanceId is missing or empty. | |
| 400 | NumberExceed.Tags | Ensure the number of tag parameters is not greater than 20. | |
| 400 | InvalidTagValue.Malformed | The specified Tag.n.Value is not valid. | The specified tag value is invalid. |
| 400 | Duplicate.TagKey | The Tag.N.Key contain duplicate key. | The specified tag key already exists. Tag keys must be unique. |
| 400 | InvalidTagKey.Malformed | The specified Tag.n.Key is not valid. | The specified Tag.N.Key parameter is invalid. |
| 400 | MissingParameter.TagKey | You must specify Tag.N.Key. | The tag key is not specified. |
| 400 | InvalidContainerId.Malformed | The specified parameter ContainerId is not valid. | The specified container ID is invalid. |
| 400 | InvalidContainerName.Malformed | The specified parameter ContainerName is not valid. | The specified container name is invalid. |
| 400 | InvalidClientToken.Malformed | The specified parameter clientToken is not valid. | |
| 400 | CmdParam.EmptyKey | Command parameters can not be empty. | |
| 400 | CmdParam.InvalidParamName | A command parameter name is invalid. | |
| 400 | CmdContent.DecodeError | The CommandContent can not be base64 decoded. | |
| 400 | InvalidInstance.NotMatch | The specified instance type does not match the command. | |
| 400 | MissingParam.Frequency | The frequency must be specified when you create a timed task. | |
| 400 | InvalidParam.Frequency | The specified frequency is invalid. | |
| 400 | ParameterKey.Duplicate | The parameter may not contain duplicate keys. | |
| 400 | Parameter.NotMatched | The parameters of creation do not match those of invocation. | |
| 400 | WindowsPasswordName.Missed | WindowsPasswordName must be specified when you create a Windows task. | |
| 400 | Parameter.Disabled | Parameters should not be passed when CreateCommand.EnableParameter is false. | |
| 400 | InvalidParameter.WorkingDir | The specified parameter WorkingDir is not valid. | |
| 400 | NumberExceed.ResourceTags | The maximum number of ResourceTags is exceeded. | |
| 400 | MissingParameter.ResourceTagKey | You must specify ResourceTag.N.Key. | |
| 400 | InvalidResourceTagKey.Malformed | The specified ResourceTag key is not valid. | |
| 400 | InvalidResourceTagValue.Malformed | The specified ResourceTag value is not valid. | |
| 400 | Duplicate.ResourceTagKey | The ResourceTag contains duplicate keys. | |
| 400 | InvalidResourceTag.InstanceNotFound | InstanceIds are not found by the specified ResourceTag. | |
| 400 | InvalidResourceTag.ConflictWithInstanceIds | The specified param ResourceTag conflicts with InstanceId. | |
| 400 | InvalidOssOutputDelivery.BucketInOtherRegion | The OSS bucket specified in the parameter OssOutputDelivery is in another region. | The OSS bucket specified in the parameter OssOutputDelivery is in another region. |
| 400 | InvalidParameter.OssOutputDelivery | The specified parameter OssOutputDelivery is not valid. | The specified parameter OssOutputDelivery is not valid. |
| 400 | InvalidOssOutputDelivery.KeyPrefixMalformed | The prefix of the OSS key specified in the parameter OssOutputDelivery is not valid. | The prefix of the OSS key specified in the parameter OssOutputDelivery 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 | InvalidOssOutputDelivery.BucketAccessDenied | The error message returned by the OSS API is: %s | |
| 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 | You've reached the limit on the count of command parameters. | |
| 403 | CmdParamName.ExceedLimit | The length of the command parameter name exceeds the limit. | |
| 403 | InstanceIds.ExceedLimit | The number of instance IDs exceeds the upper limit. | The number of specified instance IDs exceeds the upper limit. |
| 403 | Invocation.ExceedQuota | The invocation quota in the current region has been reached for today. | The maximum daily number of commands that can be run in the specified region has been reached. |
| 403 | ParameterCount.ExceedLimit | The number of command parameters exceeds the maximum number that can be set. | |
| 403 | ParameterKey.ExceedLimit | The length of the specified parameter key exceeds the maximum length that can be set. | |
| 403 | ParameterType.NotSupported | The type of parameter value is not supported. | |
| 403 | Username.ExceedLimit | The length of the username exceeds the upper limit. | The length of the username exceeds the upper limit. |
| 403 | WindowsPasswordName.ExceedLimit | The length of the WindowsPasswordName exceeds the upper limit. | |
| 403 | ParameterStore.NotSupported | Parameter Store is not supported in this region. | |
| 403 | TemporaryAccessKey.Error | The temporary accessKey is invalid. | |
| 403 | ParameterStore.InvalidParameters | The parameter is invalid in Parameter Store. | |
| 403 | ParameterStore.NoPermission | You have no access to Parameter Store. | |
| 403 | OperationDenied.BidOwnResource | Bid user can not own resource. | |
| 403 | Operation.Forbidden | The operation is not permitted. | The operation is not supported. |
| 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. |
| 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 | InvalidParameterCharset.Parameters | The parameter Parameters contains illegal charset. | The command parameter contains an illegal character set. |
| 403 | CreateServiceLinkedRole.NoPermission | You do not have permission to create ServiceLinkedRole for output delivery. | You do not have permission to create ServiceLinkedRole for output delivery. |
| 403 | InvalidTimeout.ExceedLimit | The specified parameter Timeout exceeds the upper limit. | |
| 404 | InvalidCmdType.NotFound | The specified command type does not exist. | |
| 404 | InvalidRepeatMode.NotFound | The specified repeat mode does not exist. | The specified command execution mode does not exist. |
| 404 | InvalidRegionId.NotFound | The RegionId provided does not exist in our records. | Region information error |
| 404 | InvalidInstance.NotFound | The specified instance does not exist. | |
| 404 | InvalidCmdId.NotFound | The specified command ID does not exist. | The specified CommandId parameter is invalid. Check the parameter value. You can call the DescribeCommands operation to query all available command IDs. |
| 404 | InvalidResourceGroup.NotFound | The ResourceGroup provided does not exist in our records. | The specified resource group does not exist. |
| 404 | InvalidTerminationMode.NotFound | The specified parameter TerminationMode does not exist. | The specified parameter TerminationMode does not exist. |
| 404 | InvalidOssOutputDelivery.BucketNotFound | The OSS bucket specified in the parameter OssOutputDelivery does not exist. | The OSS bucket specified in the parameter OssOutputDelivery does not exist. |
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.