CLI integration examples
Alibaba Cloud Command Line Interface (CLI) is a general-purpose tool built on OpenAPI Explorer that allows you to automate the management and maintenance of Lindorm. This topic shows how to use the Alibaba Cloud CLI to call Lindorm APIs.
Before you begin
If you are unfamiliar with the Alibaba Cloud CLI, see What is Alibaba Cloud CLI?.
Install the Alibaba Cloud CLI
You must install the Alibaba Cloud CLI before using it. The Alibaba Cloud CLI can be installed on Windows, Linux, and macOS. Select the installation method that corresponds to your operating system.
-
Windows: Install the CLI (Windows).
-
macOS: Install the CLI (macOS).
You can also use Cloud Shell provided by Alibaba Cloud to debug Alibaba Cloud CLI commands. For more information about Cloud Shell, see What is Cloud Shell?.
Configure the Alibaba Cloud CLI
Your Alibaba Cloud account (main account) has full access to all product APIs, which poses a high security risk. We strongly recommend that you create and use a RAM user for API access and daily operations.
Before you use the Alibaba Cloud CLI, you must configure your credentials and region ID. The Alibaba Cloud CLI supports multiple types of credentials. For more information, see Configure and manage credentials. This topic uses AccessKey (AK) credentials as an example. The steps are as follows:
-
Create a RAM user and grant it the required permissions. For more information, see Create a RAM user and Manage permissions for a RAM user.
ImportantThis example requires you to grant the
AliyunLindormReadOnlyAccesspermission policy to the RAM user. In a production environment, grant permissions as needed for API calls. For more information about the permission policies for Lindorm, see System permission policy reference. -
After creating and authorizing the RAM user, create an AccessKey pair for it. Record the
AccessKey IDandAccessKey Secretto configure your credentials. For more information, see Create an AccessKey. -
Obtain and record an available region ID. The Alibaba Cloud CLI uses the specified region to make API calls. For a list of available regions, see Service endpoints.
NoteWhen you use the Alibaba Cloud CLI, you can use the
--regioncommand-line option to specify a region for a command. This option overrides the region configured in your default credentials and environment variables. For more information, see Command-line options. -
Configure the AK credentials by using the RAM user's AccessKey pair. Name the configuration profile
AkProfile. For more information, see Configure and manage credentials.
Generate CLI command examples
-
Log on to the Lindorm API reference.
-
In the search box on the left, find the API to call, such as GetLindormInstance from the Instance group. In the Parameters section, enter the required parameters, such as InstanceId, and select a service endpoint, such as China (Hangzhou). Then, on the right side of the Parameters section, click the CLI Sample tab to view the generated CLI command.
-
Click the
icon to open Cloud Shell and debug the command. -
Click the
icon to copy the CLI sample to your clipboard. Then, paste it into your local shell to run it.-
When you paste the CLI sample into your local shell for debugging, note the parameter format. For more information about the parameter format for Alibaba Cloud CLI commands, see Parameter format.
-
The example generated in OpenAPI Explorer includes the
--regionoption by default. When you run the command locally, the Alibaba Cloud CLI uses the specified region and ignores the region settings in your default credentials and environment variables. You can remove or keep this option as needed.
-
-
Call an API
Command structure
The general command-line structure of Alibaba Cloud CLI is as follows. For more information, see Generate and call commands.
aliyun <command> <subcommand> [options and parameters]
Common command-line options
In the Alibaba Cloud CLI, you can use command-line options to modify the default behavior of a command or provide additional functionality. Common command-line options include:
-
--profile <profileName>: When you use the--profileoption and specify a profile nameprofileName, the CLI uses the specified profile for the command, overriding the default credentials and environment variables. -
--help: Displays help information for a command. You can add the--helpoption at any command level. For more information, see Get help information.
For more details, see Command-line options.
Example
The following example shows you how to use the Alibaba Cloud CLI to call the GetLindormInstance command in Lindorm to query information about a specified Lindorm instance. For more information about the GetLindormInstance command, see GetLindormInstance.
-
Run the command.
aliyun hitsdb GetLindormInstance --region cn-hangzhou --InstanceId 'ld-7xvyi3kkoi8dn****' -
The command returns the following response.
{ "AliUid": 168*******, "ArchVersion": "1.0", "AutoRenew": false, "ColdStorage": 0, "CoreNum": 0, "CoreSingleStorage": 0, "CreateMilliseconds": 1723098850000, "CreateTime": "2024-08-08 14:17:59", "DeletionProtection": false, "DiskCategory": "cloud_efficiency", "DiskThreshold": "80%", "DiskUsage": "0.0%", "EnableBDS": false, "EnableBlob": false, "EnableCdc": false, "EnableCompute": false, "EnableFS": false, "EnableKms": false, "EnableLProxy": false, "EnableLTS": false, "EnableLsqlVersionV3": true, "EnableML": false, "EnableMLCtrl": false, "EnablePhoenix": false, "EnableSSL": false, "EnableShs": false, "EnableStream": false, "EngineList": [ { "CoreCount": 2, "CpuCount": 4, "Engine": "lindorm", "IsLastVersion": true, "LatestVersion": "2.7.1.4", "MemorySize": 16, "Version": "2.7.1.4" } ], "EngineType": 4, "ExpiredMilliseconds": 32493801600000, "InstanceAlias": "lindormtest", "InstanceId": "ld-7xvyi3kkoi8dn****", "InstanceStatus": "ACTIVATION", "InstanceStorage": 80, "LocalCloudCategory": "cloud_ssd", "LocalCloudStorage": 0, "LogNum": 0, "LogSingleStorage": 0, "MaintainEndTime": "20:00Z", "MaintainStartTime": "16:00Z", "NetworkType": "vpc", "PayType": "POSTPAY", "RegionId": "cn-hangzhou", "RequestId": "0DA8F1BD-A2D2-****-87A4-*********", "ResourceGroupId": "rg-acfmz7u4zzr****", "ServiceType": "lindorm", "VpcId": "vpc-7xv20c7sklgdb9jsq****", "VswitchId": "vsw-7xvbnl16afanpyrhv****", "ZoneId": "cn-hangzhou-k" }