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

创建伸缩组

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

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

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

示例代码

package autoscalingexample

import (
	"fmt"

	"github.com/volcengine/volcengine-go-sdk/service/autoscaling"
	"github.com/volcengine/volcengine-go-sdk/volcengine"
	"github.com/volcengine/volcengine-go-sdk/volcengine/credentials"
	"github.com/volcengine/volcengine-go-sdk/volcengine/session"
)

func CreateScalingGroup() {
	ak, sk, region := "Your AK", "Your SK", "cn-beijing"//设置您的ak、sk和要访问的地域(本例以北京地域为例)
	config := volcengine.NewConfig().
		WithRegion(region).
		WithCredentials(credentials.NewStaticCredentials(ak, sk, ""))
	sess, err := session.NewSession(config)
	if err != nil {
		panic(err)
	}
	svc := autoscaling.New(sess)
	
	//创建伸缩组
	createScalingGroupInput := &autoscaling.CreateScalingGroupInput{
		MaxInstanceNumber: volcengine.Int32(10),//伸缩组中实例个数的最大值
		MinInstanceNumber: volcengine.Int32(1),//伸缩组中实例个数的最小值
		ScalingGroupName:  volcengine.String("scaling-group-test"),//伸缩组名称
		SubnetIds:         volcengine.StringSlice([]string{"subnet-inaimn26s8ow8gbssyxi****"}),//伸缩组中实例主网卡的子网ID
	}


	// 发起请求并处理返回或异常
	resp, err := svc.CreateScalingGroup(createScalingGroupInput)
	if err != nil {
		panic(err)
	}
	fmt.Println(resp)

相关文档