Call an SDK for Python: example
This topic shows how to use Lindorm SDK for Python to call the GetInstanceIpWhiteList operation, which retrieves the IP whitelist of a Lindorm instance.
View API documentation
Before calling API operations, read the corresponding API documentation to understand the required parameters and permissions. For more information, see List of operations by function.
Create a RAM user and grant permissions
If you have already created a Resource Access Management (RAM) user and granted the required permissions, skip this step.
-
Create a RAM user.
-
Go to the Users page of the RAM console and click Create User.
-
Set Logon Name to hitsdb-openapi-operator and set Access Mode to OpenAPI Access.
-
Click OK. On the page that appears, save the AccessKey ID and AccessKey secret of the RAM user.
-
-
Grant permissions to the RAM user.
-
Click OK.
The AliyunLindormReadOnlyAccess policy grants the RAM user read-only access to Lindorm instances. To grant full access, select AliyunLindormFullAccess instead, or create a custom policy. For more information, see RAM authorization.
-
Call an API operation
The following steps use Lindorm SDK for Python to demonstrate how to call an API operation. Lindorm SDKs for other programming languages work similarly. For more information, see Lindorm SDKs.SDK for Lindorm
Set up the environment
Download and install Python 3. To verify your installation, run:
python --version
Configure environment variables
Set the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables using your AccessKey ID and AccessKey secret.
-
Linux or macOS: Replace
<access_key_id>and<access_key_secret>with your actual values and run:export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret> -
Windows: Add
ALIBABA_CLOUD_ACCESS_KEY_IDandALIBABA_CLOUD_ACCESS_KEY_SECRETas system environment variables, set them to your AccessKey ID and AccessKey secret, and then restart your system.
Install dependencies
Run the following commands to install the required packages:
pip install alibabacloud_credentials
pip install alibabacloud_hitsdb20200615
pip install alibabacloud_tea_console
Download sample code
-
Go to GetInstanceIpWhiteList in OpenAPI Explorer.GetInstanceIpWhiteList
-
On the Parameters tab, set the
InstanceIdrequest parameter to your Lindorm instance ID. Example:ld-bp1kq0x9jogz6****. -
On the SDK Sample Code tab, select Python and click Download Project to download the sample code package.
-
Decompress the downloaded package and go to the
alibabacloud_sampledirectory.
Run the sample code
Run the following command:
python sample.py
The output is similar to:
{
"InstanceId": "ld-bp1kq0x9jogz6****",
"IpList": ["192.***.*.0"],
"RequestId": "D0E46BB4-FA32-5B19-A537-6B1B72451807"
}