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

创建VPC

最近更新时间2023.06.09 11:20:32

首次发布时间2023.06.09 11:20:32

本文介绍如何创建一个VPC。

示例代码

/**
* Example Code generated by Beijing Volcanoengine Technology.
*/
package com.volcengine.vpc.examples;

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

import com.volcengine.vpc.VpcApi;
import com.volcengine.vpc.model.*;
import java.util.*;


public class TestCreateVpc {
    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);

        VpcApi api = new VpcApi(apiClient);

        // 创建一个VPC
        CreateVpcRequest createVpcRequest = new CreateVpcRequest();
        createVpcRequest.setCidrBlock("172.XX.XX.0/12");            // VPC的网段
        createVpcRequest.setDescription("test");                    // VPC的描述
        createVpcRequest.setDnsServers(Arrays.asList("1.XX.XX.1")); // VPC的DNS服务器地址
        createVpcRequest.setVpcName("test");                        // VPC的名称

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

相关文档