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 instances and their basic information.
View the API documentation
Before you call an API operation, we recommend that you read the documentation about the API operation to learn about the parameters and permissions that are required to call the API 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 Resource Access Management (RAM) user and granted permissions to the RAM user, skip this step.
Create a RAM user.
Log on to the RAM console. In the left-side navigation pane, choose Identities > Users. On the Users page, click Create User.
On the Create User page, set Logon Name to hbase-openapi-operator and select OpenAPI Access for Access Mode.
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.
Grant permissions to the RAM user.
Go back to the Users page, find the RAM user that you created, and then click Add Permissions in the Actions column.
In the Grant Permission panel, enter
AliyunHBase
in the text box and select the AliyunHBaseReadOnlyAccess policy.NoteThe AliyunHBaseReadOnlyAccess policy grants the RAM user permissions to query ApsaraDB for HBase instances. You can also select the AliyunHBaseFullAccess policy to grant the RAM user full permissions to query and modify ApsaraDB for HBase instances or select a custom policy based on your business requirements. 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 a Python environment
Download and install Python 3. If you have installed Python, run the python --version
command to query the Python version.
Set environment variables
This section describes how to 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>
in the following commands with your AccessKey ID and AccessKey secret. Then, run the commands in sequence on your device.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 a file to add the
ALIBABA_CLOUD_ACCESS_KEY_ID
andALIBABA_CLOUD_ACCESS_KEY_SECRET
environment variables and set the variables to your AccessKey ID and AccessKey secret. Then, restart the Windows operating 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 SDK Sample Code tab, select Python for Languages and click Download Project to download the sample code package.
Decompress the sample code 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
}
}