本文介绍如何创建一台NAT网关。
/** * Example Code generated by Beijing Volcanoengine Technology. */ package com.volcengine.natgateway.examples; import com.volcengine.ApiClient; import com.volcengine.ApiException; import com.volcengine.sign.Credentials; import com.volcengine.natgateway.NatgatewayApi; import com.volcengine.natgateway.model.*; public class TestCreateNatGateway { 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); NatgatewayApi api = new NatgatewayApi(apiClient); // 创建一台NAT网关 CreateNatGatewayRequest createNatGatewayRequest = new CreateNatGatewayRequest(); createNatGatewayRequest.setSpec(CreateNatGatewayRequest.SpecEnum.valueOf(CreateNatGatewayRequest.SpecEnum.class, "Small")); // NAT网关的规格 createNatGatewayRequest.setSubnetId("subnet-2feypga30rgg059gp67ag****"); // NAT网关所属子网的ID createNatGatewayRequest.setVpcId("vpc-2feypfmenesqo59gp67yz****"); // NAT网关所属VPC的ID // 发起请求并处理返回或异常 try { CreateNatGatewayResponse response = api.createNatGateway(createNatGatewayRequest); System.out.println(response); } catch (ApiException e) { System.out.println(e.getResponseBody()); } } }