All Products
Search
Document Center

Compute Nest:Validate service instance validity

Last Updated:Jun 20, 2026

Learn how to check the validity of a service instance using the CheckOutLicense API.

Limitations

Your service must meet one of the following requirements:

  • The service is configured for custom sales.

  • The service is listed on Alibaba Cloud Marketplace.

How it works

When Compute Nest provisions a service instance, it automatically tags the underlying resources, including the service instance ID (ServiceInstanceId) and the service ID (ServiceId). The CheckOutLicense API uses these tags to identify the service instance associated with the resource that initiates the call.

  1. Obtain the ServiceId for the service from the Compute Nest console.

  2. When you call CheckOutLicense, you can pass the ServiceId as a parameter. Compute Nest compares this parameter with the service ID from the resource's tags. If they match, the API returns the license details.

API call example

This example shows how to call the CheckOutLicense API from an ECS instance belonging to a service that meets the requirements under Limitations.

  1. Get the region ID of the ECS instance

    Before calling the CheckOutLicense API, get the region ID of the ECS instance where your application is deployed. Save this ID for the next step.

    1. Run the following command to get the region ID.

      curl http://100.100.100.200/latest/meta-data/region-id
    2. Example output:

      cn-hangzhou
  2. Obtain the ServiceId from the Compute Nest console.

    image

  3. Sample request

    This example shows a call initiated from the China (Hangzhou) region. Replace the region in the URL and the ServiceId with your actual values.

    # Replace the value of ServiceId with your actual service ID.
    curl -H "Content-Type: application/json" -XPOST https://cn-hangzhou.axt.aliyun.com/computeNest/license/check_out_license -d '{"ServiceId":"service-8fff945fe6844906****"}'
  4. Example response

    {
        "code":200,
        "requestId":"6af1efb7-c59c-4cee-9094-e1e3bbefb639",
        "instanceId":"i-0jl957dfri612gxxxxxx",
        "result":{
            "RequestId":"B22723B7-FC31-18F5-A33E-1AF4C82736AA",
            "ServiceInstanceId":"si-0f14037f30c14292****",
            "LicenseMetadata":"{\"TemplateName\":\"Custom_Image_Ecs\",\"SpecificationName\":\"\",\"CustomData\":\"xxxx\"}",
            "TrialType":"NotTrial",
            "Token":"58d4574bd0d967bb431cd8936b5e80c4",
            "ExpireTime":"2024-08-28T06:27:08Z",
            "ServiceId":"service-8fff945fe6844906****",
            "Components":"{\"package_version\":\"yuncode55xxxxxxxx\",\"SystemDiskSize\":\"40\",\"DataDiskSize\":\"100\"}"
        }
     }

    The following table describes key parameters in the response.

    Parameter

    Description

    Example

    ServiceInstanceId

    The service instance ID.

    si-0f14037f30c14292****

    ServiceId

    The service ID.

    service-8fff945fe6844906****

    ExpireTime

    The expiration time of the service instance.

    2024-08-28T06:27:08Z

    LicenseMetadata

    Custom metadata.

    This data is defined in the custom sales configuration.

    {\"TemplateName\":\"Custom_Image_Ecs\",\"SpecificationName\":\"\",\"CustomData\":\"xxxx\"}

    Components

    Details of add-on billing components from Alibaba Cloud Marketplace.

    {\"package_version\":\"yuncode55xxxxxxxx\",\"SystemDiskSize\":\"40\",\"DataDiskSize\":\"100\"}

Code samples

Python

import requests
import json
import hashlib
import time
import sys
from urllib.request import urlopen

def get_region_id():
    """Get the region ID (for example, cn-hangzhou) from the Alibaba Cloud metadata service."""
    try:
        with urlopen(
            "http://100.100.100.200/latest/meta-data/region-id",
            timeout=2
        ) as response:
            return response.read().decode().strip()
    except Exception as e:
        print(f"Failed to get region ID: {str(e)}", file=sys.stderr)
        sys.exit(1)

def checkout_license():
    # Dynamically get the region ID and build the URL.
    region_id = get_region_id()
    url = f"https://{region_id}.axt.aliyun.com/computeNest/license/check_out_license"

    # Send the POST request.
    try:
        response = requests.post(
            url,
            json={
              # Optional: Include ServiceId to scope the check to a specific service.
              # If omitted, Compute Nest identifies the service from resource tags.
              # "ServiceId": "service-ec9cbf77f9be443db938"
            },
            headers={"Content-Type": "application/json"}
        )
        print(f"Request URL: {url}")
        print(f"Status Code: {response.status_code}")
        print(f"Response: {response.text}")
    except Exception as e:
        print(f"Request Failed: {str(e)}", file=sys.stderr)

if __name__ == "__main__":
    # Call the function.
    checkout_license()

Example output:

image

Java

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;     

public class CheckoutLicense {
    public static void main(String[] args) {
        try {
            // === Dynamically get the region ID ===
            String regionId = getRegionId();
            System.out.println("Detected Region ID: " + regionId);

            String checkoutLicenseString = "{}";
            // Optional: Include ServiceId to scope the check to a specific service.
            // If omitted, Compute Nest identifies the service from resource tags.
            // String checkoutLicenseString = "{\"ServiceId\": \"service-ec9cbf77f9be443db938\"}";

            // === Send the POST request ===
            String urlStr = "https://" + regionId + ".axt.aliyun.com/computeNest/license/check_out_license";
            URL url = new URL(urlStr);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "application/json");
            conn.setDoOutput(true);

            try (OutputStream os = conn.getOutputStream()) {
                byte[] input = checkoutLicenseString.getBytes("UTF-8");
                os.write(input, 0, input.length);
            }

            // === Read the response ===
            try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
                StringBuilder response = new StringBuilder();
                String responseLine;
                while ((responseLine = br.readLine()) != null) {
                    response.append(responseLine);
                }
                System.out.println("Response: " + response.toString());
            }
            conn.disconnect();
            System.out.println("Request URL: " + urlStr);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // === Get the region ID from the Alibaba Cloud metadata service ===
    private static String getRegionId() throws Exception {
        String regionIdUrl = "http://100.100.100.200/latest/meta-data/region-id";
        HttpURLConnection conn = (HttpURLConnection) new URL(regionIdUrl).openConnection();
        conn.setRequestMethod("GET");
        conn.setConnectTimeout(2000); // 2-second timeout
        conn.setReadTimeout(2000);

        try (BufferedReader in = new BufferedReader(
            new InputStreamReader(conn.getInputStream()))) {
            return in.readLine().trim();
        }
    }
}

Example output:

image