All Products
Search
Document Center

Lindorm:API usage example

Last Updated:Sep 08, 2023

This topic describes how to use Alibaba Cloud SDKs for Python and Java to call the GetInstanceIpWhiteList operation of Lindorm to query the whitelists of a Lindorm instance.

View API documentation

Before you call API operations, we recommend that you read the corresponding API documentation to understand the parameters and permissions that are required. 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.

  1. Create a RAM user.

    1. Go to the Users page of the RAM console, and then click Create User.

    2. Set the Logon Name parameter to hitsdb-openapi-operator. Select OpenAPI Access for Access Mode.

    3. Click OK. On the page that appears, save the AccessKey ID and Accesskey secret of the RAM user that you created.

  2. Authorization completed.

    1. Go to the Users page of the RAM console. Find the RAM user that you created and click Add Permissions in the Actions column.

    2. Enter AliyunLindorm in the search box and select the AliyunLindormReadOnlyAccess policy in the search results.

      Note

      The AliyunLindormReadOnlyAccess policy can grant the RAM user permissions to query Lindorm instances. You can also select the AliyunLindormFullAccess policy to grant the RAM user full permissions to query and modify Lindorm instances or select a custom policy. For more information, see RAM authorization.

    3. Click OK.

Call an API operation

This topic describes how to use Alibaba Cloud SDKs for Python and Java to call API operations. The SDKs for other languages can also be used to call API operations in a similar way. For more information, visit Lindorm SDK.

You can select the Alibaba Cloud SDK for Java or Python based on your requirements.

Prepare an environment

  • Java: Download and install JDK 8. You can run the java -version command to view the version of JDK.

  • Python: Download and install Python 3. You can run the python --version command to view the version of Python.

Configure environment variables

Configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.

  • If you use the 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 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 and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables, specify your AccessKey ID and AccessKey secret by using the environment variables, and then restart the system.

Install dependencies

  • Java: Add the following dependencies to the pom.xml configuration file of your Maven project.

    <dependency>
      <groupId>com.aliyun</groupId>
      <artifactId>hitsdb20200615</artifactId>
      <version>3.0.6</version>
    </dependency>
  • Python: Run the following commands in sequence on your terminal to install dependencies.

    pip install alibabacloud_credentials
    pip install alibabacloud_hitsdb20200615
    pip install alibabacloud_tea_console

Download the sample code

  • Java

    1. Visit GetInstanceIpWhiteList in OpenAPI Explorer where you can debug APIs.

    2. On the Parameters tab on the left, configure the request parameters. In this example, you must set the InstanceId parameter to the ID of your Lindorm instance. Example: ld-bp1kq0x9jogz6****.

    3. On the SDK Sample Code tab on the right, select Java and then click Download Project to download the sample code package.

    4. Decompress the package to a local path and import the sample code to your IDE.

  • Python

    1. Visit GetInstanceIpWhiteList in OpenAPI Explorer where you can debug APIs.

    2. On the Parameters tab on the left side of the page, configure the request parameters. In this example, you must set the InstanceId parameter to the ID of your Lindorm instance. Example: ld-bp1kq0x9jogz6****.

    3. On the SDK Sample Code tab on the right, select Python and then click Download Project to download the sample code package.

    4. Decompress the package to a local path and go to the alibabacloud_sample directory.

Run the code

  • Java

    Run the Sample.java file in the sample directory.

  • Python

    Run the following command:

    python sample.py

Sample result:

{
	"InstanceId":"ld-bp1kq0x9jogz6****",
	"IpList":["192.***.*.0"],
	"RequestId":"D0E46BB4-FA32-5B19-A537-6B1B72451807"}
}