This topic describes how to use Alibaba Cloud SDK for Java to call DescribeInstances operation. By doing so, you can obtain ECS instance configurations such as Internet IP address and instance ID.


Before you begin, make sure that you have completed the following:
  • To use Alibaba Cloud SDK for Java, you must have an Alibaba Cloud account and an AccessKey pair. You can create and view your AccessKey pair on the AccessKey Management page in the Alibaba Cloud Console.
  • You have installed Alibaba Cloud SDK for Java. For SDK version details, visit Alibaba Cloud SDK.
        <! -- -->
        <! -->

Sample code

This topic uses the following sample code as an example:
 import com.aliyuncs.profile.DefaultProfile;
 import com.aliyuncs.DefaultAcsClient;
 import com.aliyuncs.IAcsClient;
 import com.aliyuncs.exceptions.ClientException;
 import com.aliyuncs.exceptions.ServerException;
 import com.aliyuncs.ecs.model.v20140526.*;
 public class DescribeInstances {
     public static void main(String[] args) {        
        // Initialize request parameters
        DefaultProfile profile = DefaultProfile.getProfile(
                "<your-region-id>", // Your zone ID
                "<your-access-key-id>", // Your AccessKey ID
                "<your-access-key-secret>") // Your AccessKey Secret
         IAcsClient client = new DefaultAcsClient(profile);
         // Create an API request and set its parameters.
         DescribeInstancesRequest request = new DescribeInstancesRequest();
         request.setConnectTimeout(5000); // Set the connection timeout to 5000 milliseconds
         request.setReadTimeout(5000); // Set the read timeout to 5000 milliseconds.
         // Initiate the request and handle the response or exception.
         DescribeInstancesResponse response;
         try {
             response = client.getAcsResponse(request);
             for (DescribeInstancesResponse.Instance instance:response.getInstances()) {
         } catch (ServerException e) {
         } catch (ClientException e) {