Call the CheckOutLicense operation from your Elastic Compute Service (ECS)-hosted application to verify whether a service instance's license is still valid and retrieve its expiration time. Call this operation when your application starts and at regular intervals while it runs, so it can detect license changes — such as expiration or subscription upgrades — without restarting.
How it works
When Compute Nest provisions resources for a service instance, it automatically attaches two resource tags: the service instance ID (ServiceInstanceId) and the service ID (ServiceId). When your application calls CheckOutLicense, Compute Nest uses these tags to identify which service instance the calling resource belongs to, then returns the license details for that instance — including its expiration time and trial status.
Prerequisites
Before you begin, ensure that you have:
A Compute Nest service configured for custom sales, or listed on Alibaba Cloud Marketplace
An ECS instance on which your application runs
The service ID (
ServiceId) of your service, obtained from the Compute Nest console
Call CheckOutLicense
Step 1: Get the region ID
From within your ECS instance, call the instance metadata service to get the region ID. This value is required to build the API endpoint.
curl http://100.100.100.200/latest/meta-data/region-idSample response:
cn-hangzhouStore this value — you'll use it to construct the endpoint in the next step.
Step 2: Get the service ID
In the Compute Nest console, find your service and copy the ServiceId value.

Step 3: Send the request
Send a POST request to the CheckOutLicense endpoint. Replace <region-id> with the value from Step 1 and <service-id> with your service ID from Step 2.
curl -H "Content-Type: application/json" -XPOST \
https://<region-id>.axt.aliyun.com/computeNest/license/check_out_license \
-d '{"ServiceId":"<service-id>"}'ServiceId is optional. If you omit it, Compute Nest identifies the service instance from the resource tags on your ECS instance. Include it if you need to scope the check to a specific service.Step 4: Parse the response
A successful response returns HTTP 200 and a JSON body similar to the following:
{
"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 key fields for license validation:
| Parameter | Description | Example |
|---|---|---|
ExpireTime | Expiration time of the service instance. Compare this with the current time to determine whether the license is still valid. | 2024-08-28T06:27:08Z |
TrialType | Indicates whether the service instance is on a trial. | NotTrial |
ServiceInstanceId | The ID of the service instance. | si-0f14037f30c14292**** |
ServiceId | The service ID. | service-8fff945fe6844906**** |
LicenseMetadata | Custom metadata defined in your custom sales configuration. | {"TemplateName":"Custom_Image_Ecs",...} |
Components | Additional billing item information from Alibaba Cloud Marketplace. | {"package_version":"yuncode55xxxxxxxx",...} |
Code samples
Both samples dynamically fetch the region ID from the instance metadata service, build the endpoint, and call CheckOutLicense. After getting the response, check result.ExpireTime against the current time to determine whether the license is valid.
Python
import sys
import json
import requests
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():
region_id = get_region_id()
url = f"https://{region_id}.axt.aliyun.com/computeNest/license/check_out_license"
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 the resource tags.
# "ServiceId": "service-ec9cbf77f9be443db938"
},
headers={"Content-Type": "application/json"}
)
print(f"Request URL: {url}")
print(f"Status Code: {response.status_code}")
data = response.json()
print(f"Response: {json.dumps(data, indent=2)}")
# Check license validity:
# - Compare result["ExpireTime"] with the current time.
# - Check result["TrialType"] to determine the trial status.
# - Gate access to licensed features based on these values.
result = data.get("result", {})
expire_time = result.get("ExpireTime")
trial_type = result.get("TrialType")
print(f"Expiration time: {expire_time}")
print(f"Trial type: {trial_type}")
except Exception as e:
print(f"Request failed: {str(e)}", file=sys.stderr)
if __name__ == "__main__":
checkout_license()Example output:

Java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class CheckoutLicense {
public static void main(String[] args) {
try {
// Get the region ID from the instance metadata service
String regionId = getRegionId();
System.out.println("Detected region ID: " + regionId);
// Optional: include ServiceId to scope the check to a specific service.
// If omitted, Compute Nest identifies the service from the resource tags.
String requestBody = "{}";
// String requestBody = "{\"ServiceId\": \"service-ec9cbf77f9be443db938\"}";
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 = requestBody.getBytes("UTF-8");
os.write(input, 0, input.length);
}
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
response.append(line);
}
conn.disconnect();
System.out.println("Request URL: " + urlStr);
System.out.println("Response: " + response.toString());
// Check license validity:
// - Parse result.ExpireTime and compare with the current time.
// - Check result.TrialType to determine the trial status.
// - Gate access to licensed features based on these values.
} catch (Exception e) {
e.printStackTrace();
}
}
// Get the region ID from the Alibaba Cloud instance 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);
conn.setReadTimeout(2000);
try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
return in.readLine().trim();
}
}
}Example output:

Usage notes
Calling frequency
Call CheckOutLicense when your application starts, and at regular intervals while it runs. This lets your application detect changes in license status — such as expiration or subscription upgrades — without restarting.
Endpoint format
The endpoint is region-specific: https://<region-id>.axt.aliyun.com/computeNest/license/check_out_license. Always fetch the region ID dynamically from the instance metadata service rather than hardcoding it.