All Products
Search
Document Center

ENS:Java SDK call example

Last Updated:Dec 03, 2025

This topic describes how to call the DescribeEnsRegions operation using an OpenAPI to query the list of available ENS edge zones.

Step 1: View the OpenAPI documentation

Before you call an OpenAPI, read the corresponding API document, DescribeEnsRegions, to learn about the required parameters and permissions. For more information, see API overview.

  1. On the Stacks page, click Create Stack. In the Specify Template section, click Select an Existing Template.

    Note
    • If you select Create a New Template or Infrastructure Composer, you are redirected to the corresponding page.

  2. Set Template Import Method to Enter Template Content, and Template Content to ROS. Then, enter the code.

Step 2: Create a RAM user and grant permissions

Important

An Alibaba Cloud account has access permissions for all API operations. For API access or routine O&M, create and use a RAM user.

You can call this operation using an Alibaba Cloud account, a Resource Access Management (RAM) user, or a RAM role. For more information about the differences between these identities, see Identities.

In this topic, a RAM user is used to call the API operation.

  1. Create a RAM user.

    1. Log on to the RAM console.

    2. In the navigation pane on the left, choose Identities > Users.

    3. On the Users page, click Create User.

    4. On the Create User page, set the Logon Name and Display Name. Set Access Mode to Console Access.

    5. Click OK.

      After you create the RAM user, record the logon name and password. You will need them to log on to the Alibaba Cloud OpenAPI Developer Portal to call OpenAPI operations.

  2. Grant permissions to the RAM user.

    Note

    AliyunENSFullAccess: Grants the permissions to manage Edge Node Service (ENS) resources.

    AliyunENSReadOnlyAccess: Grants the read-only permissions on ENS resources.

    To create a custom policy, see Authorization information.

    1. Go to the users.

    2. Find the target RAM user and click Add Permissions in the Actions column.

    3. In the text box, enter the keyword ENS to search for the policy that you want to attach. Select the AliyunENSFullAccess policy.

    4. Click Grant permissions to complete the authorization.

  3. Go to the details page of the RAM user. On the Authentication tab, click Create AccessKey.

    For more information, see Create an AccessKey pair.

Step 3: Call the OpenAPI

This topic uses the Java SDK to call the OpenAPI. SDKs for other languages are used in a similar way. For more information, see the Edge Node Service SDK. You can also select other methods to call the operation. For more information about calling methods, see Calling methods.

Configure environment variables

Environment variables are system-level parameters specific to an operating system. They contain names and values that provide runtime settings for applications. For information about how to configure Alibaba Cloud AccessKey pairs as environment variables on different operating systems, see Configure environment variables in Linux, macOS, and Windows.

Download the sample code

  1. Go to DescribeEnsRegions.

  2. On the Parameters tab on the left, enter the required parameters.

  3. On the SDK Sample Code tab on the right, set SDK Version to v2.0 and Language to Java. Click Download Project to download the sample code package.

  4. Decompress the package on your computer and go to the alibabacloud_sample folder.

Open the project

Use IntelliJ IDEA to load the project. After the dependencies are loaded, open the src/main/java/com/aliyun/sample/Sample.java file. Add code to print the return value based on the comments in the file.

Run the project

Click Run in the upper-right corner of the IDE to view the output logs. The following content is returned in this example:

{
  "headers": {
    "access-control-allow-origin": "*",
    "date": "Tue, 18 Jul 2023 15:26:50 GMT",
    "content-length": "92",
    "keep-alive": "timeout=25",
    "x-acs-request-id": "1589E192-A47E-5224-95E2-A18F2D1ED186",
    "connection": "keep-alive",
    "content-type": "application/json;charset=utf-8",
    "etag": "9fcxMGIK+zckvQOS1NfD6GA2",
    "access-control-expose-headers": "*",
    "x-acs-trace-id": "bdfecedff57c1e8fc1b7970e909bca31"
  },
  "statusCode": 200,
  "body": {
    "code": 0,
    "ensRegions": {
      "ensRegions": [
        {
          "Area": "SouthWestChina",
          "EnName": "",
          "EnsRegionId": "cn-chongqing-unicom",
          "Province": "Chongqing",
          "Name": "China Unicom (Chongqing)"
        }
      ]
    },
    "requestId": "1589E192-A47E-5224-95E2-A18F2D1ED186"
  }
}