本示例介绍如何使用Alibaba Cloud SDK for Java调用DescribeInstanceAutoRenewAttribute接口查询预付费实例自动续费状态。

示例代码

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.ecs.model.v20140526.DescribeInstanceAutoRenewAttributeRequest;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

public class ECSOperate {
    private static final String ACCESS_KEY = "<your-access-key>";
    private static final String ACCESS_SECRET = "<your-access-key_Secret>";
    private static final String REGION_ID = "<your-region-Id>";
    private static IAcsClient client = null;

    static {
        //创建profile
        IClientProfile profile = DefaultProfile.getProfile(REGION_ID, ACCESS_KEY, ACCESS_SECRET);
        //创建client
        client = new DefaultAcsClient(profile);
    }

    public static String describeInstanceAutoRenewAttribute(FormatType formatType) {
        //构造请求
        DescribeInstanceAutoRenewAttributeRequest request = new DescribeInstanceAutoRenewAttributeRequest();
        request.setInstanceId("实例ID");
        request.setAcceptFormat(formatType);
                request.setRegionId("REGION_ID");
        try {
            //获取返回对象
            return JSON.toJSONString(client.getAcsResponse(request));
        } catch (ServerException e) {
            System.out.println("服务器异常 " + e);
            e.printStackTrace();
            return null;
        } catch (ClientException e) {
            System.out.println("参数配置异常:" + e);
            e.printStackTrace();
            return null;
        }
    }
    public static void main(String[] args) {
    System.out.println(describeInstanceAutoRenewAttribute(FormatType.JSON));
    }
}