You need to enable JavaScript to run this app.
导航

创建伸缩组

最近更新时间2023.07.19 17:54:46

首次发布时间2023.07.19 17:54:46

本文介绍如何创建一台伸缩组。

示例代码

package com.volcengine.autoscaling.examples;

import com.volcengine.ApiClient;
import com.volcengine.ApiException;
import com.volcengine.sign.Credentials;

import com.volcengine.autoscaling.AutoScalingApi;
import com.volcengine.autoscaling.model.*;
import java.util.*;


public class TestCreateScalingGroup {
    public static void main(String[] args) throws Exception {
		    //设置您的ak
        String ak = "Your AK";
        //设置您的sk
        String sk = "Your SK";
        //设置您要访问的地域
        String region = "Your Region";

				//初始化apiclient
        ApiClient apiClient = new ApiClient()
                .setCredentials(Credentials.getCredentials(ak, sk))
                .setRegion(region);

        AutoScalingApi api = new AutoScalingApi(apiClient);

				//创建伸缩组
        CreateScalingGroupRequest createScalingGroupRequest = new CreateScalingGroupRequest();
        createScalingGroupRequest.setMaxInstanceNumber(10);//伸缩组中实例个数的最大值
        createScalingGroupRequest.setMinInstanceNumber(1);//伸缩组中实例个数的最小值
        createScalingGroupRequest.setScalingGroupName("scaling-group-test");//伸缩组名称
        createScalingGroupRequest.setSubnetIds(Arrays.asList("subnet-inaimn26s8ow8gbssyxi****"));//伸缩组中实例主网卡的子网ID

        // 发起请求并处理返回或异常
        try {
            CreateScalingGroupResponse response = api.createScalingGroup(createScalingGroupRequest);
            System.out.println(response);
        } catch (ApiException e) {
            System.out.println(e.getResponseBody());
        }
    }
}

相关文档