Triggers a Cloud Assistant command on Elastic Compute Service (ECS) instances.
Usage notes
- ECS instances on which you want to run the Cloud Assistant command must meet the following requirements. If multiple ECS instances are specified and one of the instances does not meet the requirements for running the command, the call fails. You must specify instances that meet the requirements and call the InvokeCommand operation again.
- The instances are in the Running (
Running
) state. You can call the DescribeInstances operation to query instance states. - Cloud Assistant Agent is installed on the instances. For more information, see Install Cloud Assistant Agent.
- Before you run PowerShell commands on the instances, make sure that the instances have the PowerShell module configured.
- The instances are in the Running (
- The command can run only once on the instances.
- The command can run multiple times on the instances based on a schedule.
- The schedule is specified by the Frequency parameter. The results of each execution of a command do not affect the next execution of the command.
-
If you want to specify a schedule by using a cron expression, you can specify a time zone based on your business requirements. If you do not specify a time zone, the schedule is determined by the system time of the instance. Make sure that the time or time zone of the instance meets your business requirements. For more information about time zones, see Configure the NTP service for ECS instances that run CentOS 6 or Configure the NTP service for Windows instances.
To ensure that scheduled tasks can run as expected, make sure that the version of Cloud Assistant Agent is not earlier than the following ones. You can configure a command to run at a fixed interval based on a rate expression, run only once at a specified time, or run at designated times based on a cron expression. If the ClientNeedUpgrade error code is returned, you must upgrade Cloud Assistant Agent to the latest version. For more information, see Update or disable updates for Cloud Assistant Agent.
- Linux: 2.2.3.282
- Windows: 2.1.3.282
- Commands may fail to run due to instance status exceptions, network exceptions, or exceptions on Cloud Assistant Agent. If a command fails to run, no execution information is generated. For more information, see Check execution results and troubleshoot common issues.
- If you enable the custom parameter feature when you create the command, you must specify custom parameters (
Parameters
) to run the command. - Before you run a command on instances, especially new instances, we recommend that you call the DescribeCloudAssistantStatus operation to query the state of Cloud Assistant Agent installed on the instances and make sure that the return value of CloudAssistantStatus is true.
Debugging
Request parameters
Parameter | Type | Required | Example | Description |
---|---|---|---|---|
Action | String | Yes | InvokeCommand | The operation that you want to perform. Set the value to InvokeCommand. |
RegionId | String | Yes | cn-hangzhou | The region ID of the command. You can call the DescribeRegions operation to query the most recent region list. |
ResourceGroupId | String | No | rg-bp67acfmxazb4p**** | The ID of the resource group to which to assign the command executions. When you set this parameter, take note of the following items:
|
CommandId | String | Yes | c-e996287206324975b5fbe1d**** | The command ID. You can call the DescribeCommands operation to query all available command IDs. Note Common Cloud Assistant commands can be run based on their names. For more information, see View and run common Cloud Assistant commands. |
RepeatMode | String | No | Once | Specifies how to run the command. Valid values:
Default value:
Take note of the following items:
|
Timed | Boolean | No | true | Note This parameter does not take effect and is no longer used. |
Frequency | String | No | 0 */20 * * * ? | The schedule on which to run the command. You can configure a command to run at a fixed interval based on a rate expression, run only once at a specified time, or run at designated times based on a cron expression.
|
Parameters | Map | No | {"name":"Jack", "accessKey":"LTAIdyv******aRY"} | The key-value pairs of custom parameters to be passed in when the custom parameter feature is enabled. Number of custom parameters: 0 to 10.
If you want to disable the custom parameter feature, you can leave this parameter empty. |
Username | String | No | test | The username to use to run the command on instances. The username can be up to 255 characters in length.
You can also specify other usernames that already exist in the instances to run the command. For security purposes, we recommend that you run Cloud Assistant commands as a regular user. For more information, see Configure a regular user to run Cloud Assistant commands. |
WindowsPasswordName | String | No | axtSecretPassword | The name of the password to use to run the command on Windows instances. The name can be up to 255 characters in length. If you do not want to use the default System user to run the command on Windows instances, specify both WindowsPasswordName and Note If you use the root username for Linux instances or the System username for Windows instances to run the command, you do not need to specify WindowsPasswordName. |
InstanceId.N | String | No | i-bp185dy2o3o6n**** | The ID of instance N on which to run the command. You can specify up to 50 instance IDs in each request. Valid values of N: 1 to 50. |
ContainerId | String | No | ab141ddfbacfe02d9dbc25966ed971536124527097398d419a6746873fea**** | The ID of the container. Only 64-bit hexadecimal strings are supported. You can use container IDs that are prefixed with Take note of the following items:
|
ContainerName | String | No | test-container | The name of the container. Take note of the following items:
|
Timeout | Long | No | 60 | The timeout period for the command execution. Unit: seconds.
|
Tag.N.Key | String | No | TestKey | The key of tag N to add to the command task. 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 added, call the ListTagResources operation. The tag key can be up to 64 characters in length and cannot start with |
Tag.N.Value | String | No | TestValue | The value of tag N to add to the command task. Valid values of N: 1 to 20. The tag value can be an empty string. The tag value can be up to 128 characters in length and cannot contain |
ClientToken | String | No | 123e4567-e89b-12d3-a456-42665544**** | The client token that is used to ensure the idempotence of the request. You can use the client to generate the token, but you must make sure that the token is unique among different requests. The token can contain only ASCII characters and cannot exceed 64 characters in length. For more information, see How to ensure idempotence. |
Response parameters
Parameter | Type | Example | Description |
---|---|---|---|
InvokeId | String | t-7d2a745b412b4601b2d47f6a768d**** | The ID of the command task. |
RequestId | String | 473469C7-AA6F-4DC5-B3DB-A3DC0DE3**** | The request ID. |
Examples
Sample requests
http(s)://ecs.aliyuncs.com/?Action=InvokeCommand
&CommandId=c-e996287206324975b5fbe1d****
&InstanceId.1=i-bp185dy2o3o6n****
&RegionId=cn-hangzhou
&Timed=true
&Frequency=0 */20 * * * *
&Parameters={"name":"Jack", "accessKey":"LTAIdyv******aRY"}
&Username=root
&<Common request parameters>
Sample success responses
XML
format
HTTP/1.1 200 OK
Content-Type:application/xml
<InvokeCommandResponse>
<InvokeId>t-7d2a745b412b4601b2d47f6a768d****</InvokeId>
<RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3****</RequestId>
</InvokeCommandResponse>
JSON
format
HTTP/1.1 200 OK
Content-Type:application/json
{
"InvokeId" : "t-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 RegionId parameter is valid. |
400 | MissingParam.InstanceId | The parameter instanceId is missing or empty. | InstanceId.N is required. |
400 | InvalidContainerId.Malformed | The specified parameter ContainerId is not valid. | Invalid ContainerId value. |
400 | InvalidContainerName.Malformed | The specified parameter ContainerName is not valid. | Invalid ContainerName value. |
400 | InvalidClientToken.Malformed | The specified parameter clientToken is not valid. | Invalid ClientToken value. |
400 | InvalidInstance.NotMatch | The specified instance type does not match the command. | The specified command cannot be run on the specified instance. Check whether the state of the instance meets the conditions for running the Cloud Assistant command. |
400 | MissingParam.Frequency | The frequency must be specified when you create a timed task. | The Frequency parameter is required when you create a scheduled command task. |
400 | InvalidParam.Frequency | The specified frequency is invalid. | Invalid Frequency value. Check whether the specified Frequency value is valid. |
400 | Parameter.MissingValue | The parameter value of this command is required. | The parameter is required. |
400 | Parameter.Disabled | Parameters cannot be passed in when the command customization function is disabled. | The Parameters parameter is specified when the custom parameter feature is disabled. |
400 | InvalidParameter.Parameters | The specified parameter Parameters is not valid. | Invalid Parameters value. |
403 | InstanceIds.ExceedLimit | The number of instance IDs exceeds the upper limit. | The maximum number of instance IDs is exceeded. |
403 | Invocation.ExceedQuota | The invocation quota in the current region has been reached for today. | The daily maximum number of command executions in the current region is exceeded. |
403 | ParameterCount.ExceedLimit | The maximum number of parameters is exceeded. | The maximum number of specified custom parameters is exceeded. |
403 | ParameterKey.ExceedLimit | The maximum length of a parameter name is exceeded. | The key of a custom parameter exceeds 64 characters in length. |
403 | CmdContent.ExceedLimit | The maximum length of a command is exceeded. | The maximum length of the command is exceeded. Shorten your command. |
403 | ParameterKey.Duplicate | Parameter names cannot be duplicated. | A parameter that has the same name already exists. Parameter names must be unique. |
403 | Parameter.NotMatched | The passed-in parameters do not match the parameters defined when you created the command. | The custom parameters passed in do not match those specified when the command was created. |
403 | ParameterType.NotSupported | The type of parameter value is not supported. | Invalid custom parameter type. |
403 | Username.ExceedLimit | The length of the username exceeds the upper limit. | The maximum length of the username is exceeded. |
403 | WindowsPasswordName.ExceedLimit | The length of the WindowsPasswordName exceeds the upper limit. | The maximum length of WindowsPasswordName is exceeded. |
403 | WindowsPasswordName.Missed | WindowsPasswordName must be specified when you create a Windows task. | WindowsPasswordName is required. |
403 | ParameterStore.InvalidParameters | The parameter is invalid in Parameter Store. | The custom parameter in the {{oos:?}} format is not found. |
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. | The client token is already in use. |
403 | IdempotentProcessing | The previous idempotent request(s) is still processing. | A previous idempotent request is being processed. Try again later. |
404 | InvalidRepeatMode.NotFound | The specified repeat mode does not exist. | Invalid RepeatMode value. |
404 | InvalidInstance.NotFound | The specified instance does not exist. | The specified instance is not found. |
404 | InvalidCmdId.NotFound | The specified command ID does not exist. | Invalid CommandId 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 resource group ID 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.