This document describes how to initialize the configuration of Tencent Cloud Command Line Interface (TCCLI) in interactive and command line modes, and how to switch between accounts.
Prerequisites
Directions
Before using TCCLI, you must initialize its configuration to ensure that the prerequisites for using TencentCloud API are met.
Note:
The secretId, secretKey, and region used in this document are only examples. Replace them with actual information.
Interactive mode
You can enter the interactive mode for quick configuration by running the tccli configure
command.
$ tccli configure
TencentCloud API secretId [*afcQ]:AKIDz8krbsJ5yKBZQpn74WFkmLPx3*******
TencentCloud API secretKey [*ArFd]:Gu5t9xGARNpq86cd98joQYCN3*******
region: ap-guangzhou
output[json]:
secretId: the SecretId of your TencentCloud API key, which can be obtained at Manage API Key. secretKey: the SecretKey of your TencentCloud API key, which can be obtained at Manage API Key. region: the region where your Tencent Cloud product resides. Go to APIs and obtain available regions from the page of your Tencent Cloud product. For example, you can obtain Region List from the page of Cloud Virtual Machine (CVM). output: the output format of the request return packet, which is optional. Valid values: json, table, text. Default value: json.
For more information, run the tccli configure help
command.
Command line mode
In command line mode, you can configure the information in an automated script.
$ tccli configure set secretId AKIDz8krbsJ5yKBZQpn74WFkmLPx3*******
$ tccli configure set region ap-guangzhou output json
$ tccli configure get secretKey
secretKey = Gu5t9xGARNpq86cd98joQYCN3*******
$ tccli configure list
credential:
secretId = AKIDz8krbsJ5yKBZQpn74WFkmLPx3*******
secretKey = Gu5t9xGARNpq86cd98joQYCN3*******
configure:
region = ap-guangzhou
output = json
$ tccli cvm DescribeInstances --secretId AKIDz8krbsJ5yKBZQpn74WFkmLPx3****** --secretKey Gu5t9xGARNpq86cd98joQYCN3*******
Supporting multiple accounts
TCCLI supports multiple accounts, making it easier for you to use multiple configurations at the same time.
$ tccli configure --profile test
TencentCloud API secretId [*BCDP]:AKIDz8krbsJ5yKBZQpn74WFkmLPx3*******
TencentCloud API secretKey [*ArFd]:Gu5t9xGARNpq86cd98joQYCN3*******
region: ap-guangzhou
output[json]:
$ tccli configure set region ap-guangzhou output json --profile test
$ tccli configure get secretKey --profile test
$ tccli configure list --profile test
$ tccli configure remove -profile test
$ tccli cvm DescribeZones --profile test
TCCLI configuration file
After you run the tccli configure
command, the default.configure
and default.credential
files for TCCLI are generated under the ~/.tccli
directory. Content in the two files is in JSON format.
The default.configure
file records the version (the latest version by default) of the API to call, the endpoint (the nearest endpoint by default), the default output format, and the specified region. The default.credential
file records your key pairs. Example:
{
...
"cvm": {
"endpoint": "cvm.tencentcloudapi.com",
"version": "2017-03-12"
},
...
"output": "json",
"region": "ap-guanzhou",
...
}
{
"secretId": "AKIDz8krbsJ5yKBZQpn74WFkmLPx3*******",
"secretKey": "Gu5t9xGARNpq86cd98joQYCN3*******"
}
If you specified an account name in the configuration command, the configuration files corresponding to the account name are generated. For example, after you run the tccli configure --profile test
command, the test.configure
and test.credential
files are generated.
To modify content in the configuration files, you can directly edit the files or use the set
subcommand. For example, you can run the tccli configure set cvm.version 2017-03-12
command to set the version of CVM APIs to call to the default version 2017-03-12.
Configuring environment variables
TCCLI supports configuring TencentCloud API key pairs in environment variables to ensure the security of your information. For example, in Linux, you can configure a key pair in the following ways:
Use `export` command (temporary)
Write into profile file (permanent)
$ export TENCENTCLOUD_SECRET_ID=AKIDz8krbsJ5yKBZQpn74WFkmLPx3*******
$ export TENCENTCLOUD_SECRET_KEY=Gu5t9xGARNpq86cd98joQYCN3*******
$ export TENCENTCLOUD_REGION=ap-guangzhou
export TENCENTCLOUD_SECRET_ID=AKIDz8krbsJ5yKBZQpn74WFkmLPx3*******
export TENCENTCLOUD_SECRET_KEY=Gu5t9xGARNpq86cd98joQYCN3*******
export TENCENTCLOUD_REGION=ap-guangzhou
$ source /etc/profile
Note:
If you specify the same information in the command, configuration file, and environment variables, the priority order in TCCLI is command > configuration file > environment variables.
Other configurations
TCCLI supports authentication through Cloud Access Management (CAM) roles. For more information, see Role Overview.
$ tccli configure set role-arn qcs::cam::uin/***********/**** role-session-name ****
The role-arn
and role-session-name
fields support the get
and list
subcommands of configure
. You can write values into the configuration file, or specify values in the command line, in the same way that you configure secretId
and secretKey
, as shown below:
$ tccli configure get role-arn
role-arn = qcs::cam::uin/***********/****
$ tccli configure list
credential:
role-arn = qcs::cam::uin/***********/****
role-session-name = ****
$ export TENCENTCLOUD_ROLE_ARN=qcs::cam::uin/***********/****
$ export TENCENTCLOUD_ROLE_SESSION_NAME=****
$ tccli cvm DescribeZones --role-arn qcs::cam::uin/***********/**** --role-session-name ****
If your instance is bound to a role, you can use the role for authentication, without providing secretId
and secretKey
. You can use --use-cvm-role
to call APIs through the role.
$ tccli cvm DescribeZones --use-cvm-role
Note:
This method applies only to instances bound to a role. For more information, see Managing Roles.
Was this page helpful?