You need to enable JavaScript to run this app.
NAT Gateway

NAT Gateway

Copy page
Download PDF
JAVA
Creating a NAT Gateway
Copy page
Download PDF
Creating a NAT Gateway
This topic describes how to create a NAT Gateway.​
Example code​
​
/**​
* 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 {​
// Set your ak​
String ak = "Your AK";​
// Set your sk​
String sk = "Your SK";​
// Set the region you want to access​
String region = "Your Region";​
​
// Initialize apiclient​
ApiClient apiClient = new ApiClient()​
.setCredentials(Credentials.getCredentials(ak, sk))​
.setRegion(region);​
​
NatgatewayApi api = new NatgatewayApi(apiClient);​
​
// Create a NAT Gateway​
CreateNatGatewayRequest createNatGatewayRequest = new CreateNatGatewayRequest();​
createNatGatewayRequest.setSpec(CreateNatGatewayRequest.SpecEnum.valueOf(CreateNatGatewayRequest.SpecEnum.class, "Small")); // NAT Gateway specification​
createNatGatewayRequest.setSubnetId("subnet-2feypga30rgg059gp67ag****"); // ID of the NAT Gateway's subnet​
createNatGatewayRequest.setVpcId("vpc-2feypfmenesqo59gp67yz****"); // ID of the VPC where the NAT Gateway is located​
​
// Initiate the request and handle the response or exception​
try {​
CreateNatGatewayResponse response = api.createNatGateway(createNatGatewayRequest);​
System.out.println(response);​
} catch (ApiException e) {​
System.out.println(e.getResponseBody());​
}​
}​
}​
​
Related documents​
​
Last updated: 2026.07.09 19:16:54