tencent cloud

Feedback

InvokeCommand

Last updated: 2022-05-23 15:23:48

1. API Description

Domain name for API request: tat.tencentcloudapi.com.

This API is used to trigger a command on the specified instance and returns the execution activity ID (inv-xxxxxxxx) on success. Each execution activity has one or more execution tasks (invt-xxxxxxxx) and each execution task indicates an execution record on a CVM or Lighthouse instance.

  • If the agent is not installed on the instance or is offline, an error is returned.
  • If the command type is not supported by the agent runtime environment, an error is returned.
  • The specified instance needs to be in a VPC network.
  • The specified instance needs to be in the RUNNING status.
  • Only one type of instances (CVM or Lighthouse) can be specified in a single request.

A maximum of 20 requests can be initiated per second for this API.

We recommend you to use API Explorer
Try it
API Explorer provides a range of capabilities, including online call, signature authentication, SDK code generation, and API quick search. It enables you to view the request, response, and auto-generated examples.

2. Input Parameters

The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.

Parameter Name Required Type Description
Action Yes String Common Params. The value used for this API: InvokeCommand.
Version Yes String Common Params. The value used for this API: 2020-10-28.
Region Yes String Common Params. For more information, please see the list of regions supported by the product.
CommandId Yes String ID of the command to be triggered.
InstanceIds.N Yes Array of String IDs of instances about to execute commands. At most 100 IDs are allowed.
Parameters No String Custom parameters of the command. The field type is JSON encoded string. For example, {"varA": "222"}.
key is the name of the custom parameter and value is the default value. Both key and value are strings.
If no parameter value is provided, the DefaultParameters of the command is used.
Up to 20 custom parameters are supported.
The name of the custom parameter cannot exceed 64 characters and can contain [a-z], [A-Z], [0-9] and [-_].
Username No String The username used to execute the command on the CVM or Lighthouse instance.
The principle of the least privilege is the best practice for permission management. We recommend you execute TAT commands as a general user. If this is not specified, the Username of the command is used by default.
WorkingDirectory No String Execution path of the command. The WorkingDirectory of the command is used by default.
Timeout No Integer Command timeout period. Value range: [1, 86400]. The Timeout of the command is used by default.
OutputCOSBucketUrl No String The COS bucket URL for uploading logs. The URL must start with https, such as https://BucketName-123454321.cos.ap-beijing.myqcloud.com.
OutputCOSKeyPrefix No String The COS bucket directory where the logs are saved. Check below for the rules of the directory name.
1. It must be a combination of number, letters, and visible characters. Up to 60 characters are allowed.
2. Use a slash (/) to create a subdirectory.
3. ".." can not be used as the folder name. It cannot start with a slash (/), and cannot contain consecutive slashes.

3. Output Parameters

Parameter Name Type Description
InvocationId String Execution activity ID.
RequestId String The unique request ID, which is returned for each request. RequestId is required for locating a problem.

4. Example

Example1 Triggering a command on a Lighthouse instance

Input Example

POST / HTTP/1.1
Host: tat.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: InvokeCommand
<Common request parameters>

{
    "CommandId": "cmd-ffxdx79i",
    "InstanceIds": [
        "lhins-ar5wyn40"
    ]
}

Output Example

{
  "Response": {
    "RequestId": "41417f50-51b5-4c8d-85b7-f6c508cb228f",
    "InvocationId": "inv-8xgjrytm"
  }
}

5. Developer Resources

SDK

TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.

Command Line Interface

6. Error Code

The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.

Error Code Description
FailedOperation.CVMError Failed to access the CVM.
FailedOperation.LighthouseError Failed to access the Lighthouse instance.
InternalError Internal error.
InvalidParameter Invalid parameter.
InvalidParameter.InvalidUsername Invalid username.
InvalidParameterValue Invalid parameter value.
InvalidParameterValue.AgentUnsupportedCommandType TAT Agent does not support this command type.
InvalidParameterValue.InconsistentInstance Inconsistent instance type.
InvalidParameterValue.InvalidCommandId Invalid CommandId.
InvalidParameterValue.InvalidInstanceId Invalid instance ID.
InvalidParameterValue.InvalidOutputCOSBucketUrl Invalid OutputCOSBucketUrl.
InvalidParameterValue.InvalidOutputCOSKeyPrefix Invalid OutputCOSKeyPrefix.
InvalidParameterValue.LackOfParameterInfo The custom parameter feature is enabled, but custom parameters are missing.
InvalidParameterValue.ParameterDisabled The custom parameter feature is not enabled.
InvalidParameterValue.ParameterInvalidJsonFormat The parameter is not a valid JSON string.
InvalidParameterValue.ParameterKeyContainsInvalidChar The parameter key contains invalid characters.
InvalidParameterValue.ParameterKeyDuplicated Duplicate parameter keys.
InvalidParameterValue.ParameterKeyLenExceeded The parameter key is too long.
InvalidParameterValue.ParameterNumberExceeded Too many parameters.
InvalidParameterValue.ParameterValueNotString The parameter value is not a string.
InvalidParameterValue.SupportParametersOnlyIfEnableParameter The custom parameter feature is not enabled.
ResourceNotFound.CommandNotFound The command does not exist.
ResourceNotFound.InstanceNotFound The instance does not exist.
ResourceUnavailable.AgentNotInstalled TAT Agent is not installed.
ResourceUnavailable.AgentStatusNotOnline TAT Agent is offline.
ResourceUnavailable.InstanceStateNotRunning The instance is not running.
UnauthorizedOperation.CamAuthFailed CAM authentication failed.
UnauthorizedOperation.InvalidToken Invalid token.
UnauthorizedOperation.MFAExpired The Multi-factor authentication (MFA) code expired.
UnauthorizedOperation.MFANotFound Multi-factor authentication (MFA) does not exist.
Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support