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 SetInstancesProtection() {
	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)
	
	//设置实例保护状态
	setInstancesProtectionInput := &autoscaling.SetInstancesProtectionInput{
		InstanceIds:          volcengine.StringSlice([]string{"i-ybmike5l70l8j1ha****"}),//待设置保护状态的实例ID
		ProtectedFromScaleIn: volcengine.Bool(true),//实例保护状态,此处表示开启实例保护
		ScalingGroupId:       volcengine.String("scg-ybmssdnnhn5pkgyd****"),伸缩组ID
	}



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

相关文档