All Products
Search
Document Center

Enterprise Distributed Application Service:Manage instance groups for an ECS application by using the EDAS Java SDK

Last Updated:Mar 11, 2026

When you run multiple versions of an application on Elastic Compute Service (ECS) instances, you need a way to isolate versions, route traffic selectively, and perform canary releases without redeploying the entire fleet. Enterprise Distributed Application Service (EDAS) instance groups let you partition ECS instances so that each group runs a different application version. You can then shift traffic between groups, validate a new version on a small group, and promote it to the rest.

This topic covers five operations with the EDAS SDK for Java:

Quick start

The following example creates an instance group named Beta, associates it with an application version, and prints the resulting group ID. Replace the placeholder IDs with your own values.

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.edas.model.v20170801.InsertDeployGroupRequest;
import com.aliyuncs.edas.model.v20170801.InsertDeployGroupResponse;

public class QuickStart {
    public static void main(String[] args) throws Exception {
        String regionId = "cn-hangzhou";
        String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");

        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);

        InsertDeployGroupRequest request = new InsertDeployGroupRequest();
        request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
        request.setGroupName("Beta");
        request.setInitPackageVersionId("3fc52328-8746-4422-a742-94e0cfc7****");

        InsertDeployGroupResponse response = client.getAcsResponse(request);
        System.out.println("GroupName=" + response.getDeployGroupEntity().getGroupName()
            + "\nId=" + response.getDeployGroupEntity().getId());
    }
}

Expected output:

GroupName=Beta
Id=941be68c-4aac-48a1-88fe-c9ad1502****

For more operations such as moving instances between groups, configuring JVM and Tomcat settings, or deleting groups, see the sections below.

How instance groups work

When you create an application in the EDAS console, EDAS automatically creates a default group (_DEFAULT_GROUP). The default group cannot be deleted and is sufficient for single-version deployments.

For multi-version deployments, create additional groups to isolate versions. For example, an application named itemcenter runs on 10 ECS instances. Six instances belong to the default group and four belong to a beta group. Each group can have its own JVM, Tomcat, launch template, and Server Load Balancer (SLB) settings.

Before you begin

Before you call any of the operations in this topic, make sure that you have:

  • The EDAS SDK for Java installed. See Use EDAS SDK for Java to call EDAS API

  • The region ID where your application runs (for example, cn-hangzhou)

  • (Conditional) The application version ID, if you plan to create an instance group. Call ListHistoryDeployVersion and use the PackageVersion.Id value

  • (Conditional) The Elastic Compute Container (ECC) ID, if you plan to move an ECS instance between groups. Call ListApplicationEcc and use the EccId value

  • ECS instances created (for example, i-bp13o01lzmbsvhsl****)

  • An ECS cluster created. See Create an ECS cluster by calling an API operation. If you already have a cluster, call ListCluster and use the ClusterId value (for example, 369d06d7-450b-4f3d-bf75-9536fcd9****)

Common client setup

All examples in this topic share the same client initialization. Configure it once before running any operation:

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;

// Replace with the region ID where your application runs
String regionId = "cn-hangzhou";

// Retrieve AccessKey credentials from environment variables
String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");

DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile);

Set the following environment variables before running the code:

VariableDescription
ALIBABA_CLOUD_ACCESS_KEY_IDAccessKey ID of your Alibaba Cloud account or a RAM user
ALIBABA_CLOUD_ACCESS_KEY_SECRETAccessKey secret of your Alibaba Cloud account or a RAM user

Create an instance group

Call InsertDeployGroup to create an instance group and associate it with an application version.

Parameters

ParameterTypeRequiredDescription
AppIdStringYesApplication ID.
GroupNameStringYesGroup name. Supports letters, digits, underscores (_), and periods (.). Maximum 64 characters.
InitPackageVersionIdStringYesDeployment package version ID to initialize the group. Get this by calling ListHistoryDeployVersion.

Sample code

import com.aliyuncs.edas.model.v20170801.InsertDeployGroupRequest;
import com.aliyuncs.edas.model.v20170801.InsertDeployGroupResponse;

InsertDeployGroupRequest request = new InsertDeployGroupRequest();
request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
request.setGroupName("Beta");
request.setInitPackageVersionId("3fc52328-8746-4422-a742-94e0cfc7****");

try {
    InsertDeployGroupResponse response = client.getAcsResponse(request);
    System.out.println("GroupName=" + response.getDeployGroupEntity().getGroupName()
        + "\nId=" + response.getDeployGroupEntity().getId());
} catch (com.aliyuncs.exceptions.ClientException e) {
    // Common errors:
    // - Invalid AppId: The specified application does not exist.
    // - Duplicate GroupName: A group with this name already exists.
    e.printStackTrace();
}

Sample response

GroupName=Beta
Id=941be68c-4aac-48a1-88fe-c9ad1502****

Verify the result

Call ListDeployGroup and check whether the new group name appears in the response:

{
  "DeployGroupList": {
    "DeployGroup": [
      {
        "GroupName": "Beta",
        "AppId": "6bbc57a2-a017-4bec-b521-49a15bd3****",
        "GroupId": "941be68c-4aac-48a1-88fe-c9ad1502****"
      }
    ]
  },
  "Message": "success",
  "Code": 200
}

Move an ECS instance to a different group

Call ChangeDeployGroup to move an ECS instance from one instance group to another.

Note

Only one ECS instance can be moved per API call.

Parameters

ParameterTypeRequiredDescription
AppIdStringYesApplication ID.
EccInfoStringYesECC ID of the ECS instance. Get this by calling ListApplicationEcc.
GroupNameStringYesTarget group name. Use _DEFAULT_GROUP to move the instance back to the default group.
ForceStatusBooleanNoForce the move when the deployment package version of the ECC differs from the target group. Default: false.

Sample code

import com.aliyuncs.edas.model.v20170801.ChangeDeployGroupRequest;
import com.aliyuncs.edas.model.v20170801.ChangeDeployGroupResponse;

ChangeDeployGroupRequest request = new ChangeDeployGroupRequest();
request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
request.setEccInfo("4009a824-ce33-4ba0-9ca2-346249a9****");
request.setGroupName("Beta");
request.setForceStatus(true);

try {
    ChangeDeployGroupResponse response = client.getAcsResponse(request);
    System.out.println("Message=" + response.getMessage()
        + "\nChangeOrderId=" + response.getChangeOrderId());
} catch (com.aliyuncs.exceptions.ClientException e) {
    // Common errors:
    // - Invalid EccInfo: The specified ECC does not exist.
    // - Version mismatch: Set ForceStatus to true to force the move.
    e.printStackTrace();
}

Sample response

Message=success
ChangeOrderId=369d06d7-450b-4f3d-bf75-9536fcd9****

Verify the result

Call ListApplicationEcc and confirm that the GroupId for the ECS instance matches the target group:

{
  "EccInfoList": {
    "EccInfo": [
      {
        "EcuId": "8287bcf6-cde3-4377-8906-086d2c32****",
        "GroupId": "941be68c-4aac-48a1-88fe-c9ad1502****",
        "AppId": "6bbc57a2-a017-4bec-b521-49a15bd3****",
        "EccId": "02cdcdfa-f22b-45e6-8a0f-a738c766****"
      }
    ]
  },
  "Message": "success",
  "Code": 200
}

Set JVM parameters for a group

Call UpdateJvmConfiguration to set Java Virtual Machine (JVM) parameters for a specific instance group.

Parameters

ParameterTypeRequiredDescription
AppIdStringYesApplication ID.
GroupIdStringYesInstance group ID. Get this by calling ListDeployGroup.
MinHeapSizeIntegerNoInitial heap size in MB.
MaxHeapSizeIntegerNoMaximum heap size in MB.
MaxPermSizeIntegerNoPermanent generation size in MB.
OptionsStringNoCustom JVM options (for example, -Dproperty=value).

Sample code

import com.aliyuncs.edas.model.v20170801.UpdateJvmConfigurationRequest;
import com.aliyuncs.edas.model.v20170801.UpdateJvmConfigurationResponse;

UpdateJvmConfigurationRequest request = new UpdateJvmConfigurationRequest();
request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
request.setGroupId("941be68c-4aac-48a1-88fe-c9ad1502****");
request.setMinHeapSize(500);
request.setMaxHeapSize(500);
request.setMaxPermSize(500);
request.setOptions("-Dproperty=value");

try {
    UpdateJvmConfigurationResponse response = client.getAcsResponse(request);
    System.out.println("Message=" + response.getMessage());
} catch (com.aliyuncs.exceptions.ClientException e) {
    // Common errors:
    // - Invalid GroupId: The specified instance group does not exist.
    e.printStackTrace();
}

Sample response

Message=success

Verify the result

Call GetJvmConfiguration to confirm the updated JVM settings:

{
  "Message": "success",
  "JvmConfiguration": {
    "Options": "-Dproperty=value",
    "MaxPermSize": 500,
    "MaxHeapSize": 500,
    "MinHeapSize": 500
  },
  "Code": 200
}

Set Tomcat parameters for a group

Call UpdateContainerConfiguration to set Tomcat container parameters for a specific instance group.

Parameters

ParameterTypeRequiredDescription
AppIdStringYesApplication ID.
GroupIdStringYesInstance group ID. Get this by calling ListDeployGroup.
ContextPathStringNoTomcat context path. Valid values: empty string, null, a WAR package name, ROOT (root directory), or a custom string.
HttpPortIntegerNoApplication port (for example, 8080).
MaxThreadsIntegerNoMaximum number of threads.
URIEncodingStringNoURI encoding scheme. Valid values: ISO-8859-1, GBK, GB2312, UTF-8.
UseBodyEncodingBooleanNoWhether to use the request body encoding scheme for URI query parameters. Default: false.

Sample code

import com.aliyuncs.edas.model.v20170801.UpdateContainerConfigurationRequest;
import com.aliyuncs.edas.model.v20170801.UpdateContainerConfigurationResponse;

UpdateContainerConfigurationRequest request = new UpdateContainerConfigurationRequest();
request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
request.setGroupId("941be68c-4aac-48a1-88fe-c9ad1502****");
request.setContextPath("");
request.setHttpPort(8080);
request.setMaxThreads(20);
request.setURIEncoding("ISO-8859-1");
request.setUseBodyEncoding(true);

try {
    UpdateContainerConfigurationResponse response = client.getAcsResponse(request);
    System.out.println("Message=" + response.getMessage());
} catch (com.aliyuncs.exceptions.ClientException e) {
    // Common errors:
    // - Invalid GroupId: The specified instance group does not exist.
    e.printStackTrace();
}

Sample response

Message=success

Verify the result

Call GetContainerConfiguration to confirm the updated Tomcat settings:

{
  "Message": "success",
  "ContainerConfiguration": {
    "HttpPort": 8080,
    "ContextPath": "ROOT",
    "UseBodyEncoding": true,
    "URIEncoding": "ISO-8859-1",
    "MaxThreads": 20
  },
  "Code": 200
}

Delete an instance group

Call DeleteDeployGroup to delete an instance group.

Important

An instance group that contains ECS instances cannot be deleted. Move all instances to another group first. See Move an ECS instance to a different group.

Parameters

ParameterTypeRequiredDescription
AppIdStringYesApplication ID.
GroupNameStringYesName of the instance group to delete.

Sample code

import com.aliyuncs.edas.model.v20170801.DeleteDeployGroupRequest;
import com.aliyuncs.edas.model.v20170801.DeleteDeployGroupResponse;

DeleteDeployGroupRequest request = new DeleteDeployGroupRequest();
request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
request.setGroupName("Beta");

try {
    DeleteDeployGroupResponse response = client.getAcsResponse(request);
    System.out.println("Message=" + response.getMessage()
        + "\nData=" + response.getData());
} catch (com.aliyuncs.exceptions.ClientException e) {
    // Common errors:
    // - Group not empty: Move all instances to another group before deleting.
    // - Invalid GroupName: The specified group does not exist.
    e.printStackTrace();
}

Sample response

Message=success
Data=1

Verify the result

Call ListDeployGroup and confirm the deleted group no longer appears in the response:

{
  "DeployGroupList": {
    "DeployGroup": [
      {
        "GroupName": "_DEFAULT_GROUP",
        "AppId": "6bbc57a2-a017-4bec-b521-49a15bd3****",
        "GroupId": "941be68c-4aac-48a1-88fe-c9ad1502****"
      }
    ]
  },
  "Message": "success",
  "Code": 200
}

Error handling

All EDAS SDK operations throw ClientException (client-side errors such as invalid parameters or network issues) or ServerException (server-side errors). The following table lists common error scenarios and solutions:

OperationError scenarioSolution
InsertDeployGroupDuplicate group nameChoose a different group name or query existing groups with ListDeployGroup.
InsertDeployGroupInvalid InitPackageVersionIdCall ListHistoryDeployVersion to get valid version IDs.
ChangeDeployGroupVersion mismatch between ECC and target groupSet ForceStatus to true to force the move.
ChangeDeployGroupInvalid EccInfoCall ListApplicationEcc to get valid ECC IDs.
DeleteDeployGroupGroup contains ECS instancesMove all instances to another group before deleting.
All operationsInvalid AppIdVerify the application exists and you have access to it.

Related API operations

OperationDescription
InsertDeployGroupCreate an instance group.
ChangeDeployGroupMove an ECS instance to a different group.
UpdateJvmConfigurationSet JVM parameters for an instance group.
UpdateContainerConfigurationSet Tomcat parameters for an instance group.
DeleteDeployGroupDelete an instance group.
ListDeployGroupQuery instance groups for an application.
ListHistoryDeployVersionQuery historical deployment versions.
ListApplicationEccQuery ECC information for an application.
GetJvmConfigurationQuery JVM settings for an instance group.
GetContainerConfigurationQuery Tomcat settings for an instance group.
ListClusterQuery ECS clusters.