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

创建VPN网关

最近更新时间2023.07.05 15:21:25

首次发布时间2023.07.05 15:21:25

本文介绍如何创建VPN网关。

示例代码

package vpnexample

import (
	"fmt"

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

func CreateVpnGateway() {
	// 设置您的AK、SK和要访问的地域。
	ak, sk, region := "Your AK", "Your SK", "Region"
	config := volcengine.NewConfig().
		WithRegion(region).
		WithCredentials(credentials.NewStaticCredentials(ak, sk, ""))
	sess, err := session.NewSession(config)
	if err != nil {
		panic(err)
	}
	svc := vpn.New(sess)
	// 创建VPN网关。
	createVpnGatewayInput := &vpn.CreateVpnGatewayInput{
		Bandwidth:      volcengine.Int64(5), // 设置VPN网关出云方向的带宽规格,单位:Mbps。取值:5、10、20、50、100、200、500、1000。
		BillingType:    volcengine.Int64(1), // 设置VPN网关的计费类型。当前仅支持“1”(包年包月)。
		Description:    volcengine.String("test"), // 设置VPN网关的描述信息。
		Period:         volcengine.Int64(1), // 设置包年包月类型VPN网关购买的时长。
		PeriodUnit:     volcengine.String("Month"), // 设置包年包月类型VPN网关购买时长的单位,Month(月),Year(年)。
		SubnetId:       volcengine.String("subnet-2fewbgn7jbk0059gp67ap****"), // 设置VPN网关使用子网的ID。
		VpcId:          volcengine.String("vpc-12bhs1ivo6p6o17q7y2x3****"), // 设置VPN网关所在VPC的ID。
		VpnGatewayName: volcengine.String("test"), // 设置VPN网关的名称。
	}

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

相关文档