This topic describes how to call the DescribeInstances operation by using ApsaraDB for HBase SDK for Python to query a list of ApsaraDB for HBase clusters and their basic information.
View API documentation
Before you call an operation, we recommend that you read the API documentation and get yourself familiar with the parameters and permissions that are required to call the operation. For more information, see List of operations by function.
Create a RAM user and grant permissions to the RAM user
If you have created a RAM user and granted permissions to the RAM user, you can skip this step.
To create a RAM user, perform the following steps:
Log on to the RAM console. In the left-side navigation pane, choose Identities > Users. On the Users page, click Create User.
Set Logon Name to hbase-openapi-operator and Access Mode to Using permanent AccessKey to access.
Click OK. The RAM user is created. The system automatically generates an AccessKey ID and an AccessKey secret for the RAM user. Record the AccessKey ID and AccessKey secret.
To grant permissions to the RAM user, perform the following steps:
Go back to the Users page, find the RAM user that you created, and then click Add Permissions in the Actions column.
In the Add Permissions panel, search for
AliyunHBase
in the text box and select the AliyunHBaseReadOnlyAccess policy.NoteThe AliyunHBaseReadOnlyAccess policy has permissions to query ApsaraDB for HBase clusters. You can also select the AliyunHBaseFullAccess policy or define a policy. The AliyunHBaseFullAccess policy has all permissions on ApsaraDB for HBase clusters, including querying and modifying ApsaraDB for HBase clusters. For more information, see Customize a RAM policy.
Click OK.
Call an operation
This section describes how to call the DescribeInstances operation by using ApsaraDB for HBase SDK for Python. For more information about using ApsaraDB for HBase SDKs for other programming languages, see ApsaraDB for HBase SDKs.
Prepare the Python environment
Download and install Python 3. If you have installed Python, you can run the python --version
command to query the Python version.
Set environment variables
Configure the ALIBABA_CLOUD_ACCESS_KEY_ID
and ALIBABA_CLOUD_ACCESS_KEY_SECRET
environment variables.
If you use a Linux or macOS operating system, replace
<access_key_id>
and<access_key_secret>
with the AccessKey ID and AccessKey secret of the RAM user, and then run the following commands:export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>
If you use a Windows operating system, create an environment variable file, add the
ALIBABA_CLOUD_ACCESS_KEY_ID
andALIBABA_CLOUD_ACCESS_KEY_SECRET
environment variables to the environment variable file, and then write the AccessKey ID and AccessKey secret of the RAM user. Restart the Windows system.
Install dependencies
Run the following commands on your device to install environment dependencies:
pip install alibabacloud_credentials
pip install alibabacloud_hbase20190101
pip install alibabacloud_tea_console
Download sample code
Click DescribeInstances to open the DescribeInstances operation page on the OpenAPI Portal.
On the Parameters tab, set the required parameters. For this example, enter cn-hangzhou for RegionId.
On the right-side SDK Sample Code tab, select Python for the Languages parameter and click Download Project to download the sample code package.
Decompress the package on your device and go to the alibabacloud_sample directory.
Run the sample code
Run the following command:
python sample.py
Sample result:
[
LOG
] {
"headers": {
"date": "Mon, 24 Jul 2023 09:56:30 GMT",
"content-type": "application/json;charset=utf-8",
"content-length": "943",
"connection": "keep-alive",
"keep-alive": "timeout=25",
"access-control-allow-origin": "*",
"access-control-expose-headers": "*",
"x-acs-request-id": "C20BAA8E-C543-58F1-A611-9C812336****",
"x-acs-trace-id": "63ca81587ddddeb0d47443462b3d****",
"etag": "919xrdSHGE5LzH4To3ra****"
},
"body": {
"Instances":{
"Instance": [
{
"BackupStatus": "open",
"ClusterId": "ld-bp1st3v9780tk****",
"ClusterName": "Test",
"ClusterType": "cluster",
"ColdStorageStatus": "open",
"CoreDiskCount": 4,
"CoreDiskSize": 100,
"CoreDiskType": "cloud_ssd",
"CoreInstanceType": "hbase.sn2.large",
"CoreNodeCount": 4,
"CreatedTime": "2023-07-24T17:44:54",
"CreatedTimeUTC": "2023-07-24T09:44:54Z",
"Engine": "hbaseue",
"InstanceId": "ld-bp1st3v9780tk****",
"InstanceName": "Test",
"IsDeletionProtection": false,
"IsHa": true,
"MajorVersion": "2.0",
"MasterDiskSize": 0,
"MasterDiskType": "",
"MasterInstanceType": "hbase.sn1.large",
"MasterNodeCount": 2,
"ModuleId": 0,
"NetworkType": "VPC",
"PayType": "Postpaid",
"RegionId": "cn-hangzhou",
"ResourceGroupId": "rg-acfmz7u4zzr****",
"Status": "ACTIVATION",
"Tags": {
"Tag": []
},
"VpcId": "vpc-bp16crlc5o2dmwi8p****",
"VswitchId": "vsw-bp1sueafuqh4ly8ae****",
"ZoneId": "cn-hangzhou-f"
}
]
},
"PageNumber": 1,
"PageSize": 10,
"RequestId": "C20BAA8E-C543-58F1-A611-9C812336****",
"TotalCount": 1
}
}