Creates a NAT Gateway.

API description

Before you create a NAT Gateway, note the following:

  • A NAT Gateway and a self-hosted SNAT Gateway cannot coexist in a VPC.
  • After a NAT Gateway is created, a route entry of which the destination CIDR block is 0.0.0.0/0 and the next hop is the NAT Gateway is automatically added to the route table of the VPC. This means that traffic can be routed to the NAT Gateway.
  • If a route entry of which the destination CIDR block is 0.0.0.0/0 already exists in the route table of the VPC, you must delete the route entry. Otherwise, the NAT Gateway cannot be created.

Make the API call

You can use OpenAPI Explorer to make API calls, search for API calls, perform debugging, and generate SDK example code.

Request parameters

Parameter Type Required? Example value Description
Action String  Yes CreateNatGateway

The name of this action. Value: CreateNatGateway

RegionId String  Yes cn-hangzhou

The ID of the region to which the NAT Gateway belongs.

To query the region ID, call DescribeRegions.

VpcId String  Yes vpc-bp1di7uewzmtvfuq8****

The ID of the VPC.

Name String No fortest

The name of the NAT Gateway.

The name must be 2 to 128 characters in length and must start with a letter. It cannot start with http:// or https://. The name can contain digits, periods (.), underscores (_), and hyphens (-).

If you do not specify this parameter, the NAT Gateway ID is used by default.

Description String No testnat

The description of the NAT Gateway.

The description must be 2 to 256 characters in length and cannot start with http:// or https://.

ClientToken String No shefffxxddjehfh123

A client token that guarantees the idempotency of the request. The value of this parameter is generated by the client. The value must be unique among different requests and must be 1 to 64 ASCII characters in length.

Spec String No Small

The specification of the NAT Gateway. Valid values:

  • Small (default)
  • Middle
  • Large
  • XLarge.1
BandwidthPackage.N.IpCount Integer No 5

The number of public IP addresses in the NAT bandwidth package. Value range: 1 to 50

N indicates the sequential position of the bandwidth package. Value range of N: 1 to 4

Note This parameter is valid only if you have purchased a NAT bandwidth package before November 3, 2017. If no NAT bandwidth package exists under your account before November 3, 2017, you can associate one or more Elastic IP addresses with the NAT Gateway.
BandwidthPackage.N.Bandwidth Integer No 5

The bandwidth of the n-th NAT bandwidth package. Value range: 5 to 5000

Note This parameter is valid only if you have purchased a NAT bandwidth package before November 3, 2017. If no NAT bandwidth package exists under your account before November 3, 2017, you can associate one or more Elastic IP addresses with the NAT Gateway.
BandwidthPackage.N.Zone String No cn-hangzhou-b

The zone to which the n-th NAT bandwidth package belongs. If you do not specify this parameter, the bandwidth package is randomly allocated to a zone.

Connectivity is not affected if the IP addresses of the NAT bandwidth package and the backend ECS instance belong to different zones. However, if they belong to the same zone, the latency can be shortened.

Note This parameter is valid only if you have purchased a NAT bandwidth package before November 3, 2017. If no NAT bandwidth package exists under your account before November 3, 2017, you can associate one or more Elastic IP addresses with the NAT Gateway.
BandwidthPackage.N.ISP String No BGP

The ISP type of the n-th NAT bandwidth package. Default value: BGP (multi-path)

InstanceChargeType String No PostPaid

The billing method. Set this value to PostPaid (pay-as-you-go). For more information, see Pay-as-you-go.

PricingCycle String No Month

Optional. The billing cycle of the subscription plan.

Duration String No 1

Leave this parameter blank.

AutoPay Boolean No false

Optional. Indicates whether to pay the bill automatically.

VSwitchId String No vsw-bp1e3se98n9fq8hle****

The ID of the VSwitchId to which the NAT Gateway belongs.

NatType String No Normal

The type of the NAT Gateway. Valid value: Normal

InternetChargeType String No PayByTraffic

The billing method for network usage of the NAT bandwidth package. Set this value to PayByTraffic.

Response parameters

Parameter Type Example value Description
RequestId String  2315DEB7-5E92-423A-91F7-4C1EC9AD97C3

The ID of the request.

NatGatewayId String ngw-112za33e4****

The ID of the NAT Gateway.

This parameter value is generated by the system and is globally unique. It is the only ID that can be used to access the NAT Gateway.

ForwardTableIds List ftb-11tc6xgmv****

The list of forwarding tables.

SnatTableIds List stb-SnatTableIds****

The ID of the SNAT table.

BandwidthPackageIds List bwp-11odxu2k7****

The list of NAT bandwidth packages.

Examples

Request example

https://vpc.aliyuncs.com/?Action=CreateNatGateway
&RegionId=cn-hangzhou
&VpcId= vpc-bp1di7uewzmtvfuq8****
&<CommonParameters>

Response example

XML format

<CreateNatGatewayResponse>
    <BandwidthPackageIds>
  </BandwidthPackageIds>
    <RequestId>7C01CA72-73FD-4056-B16A-42E392D47625</RequestId>
    <SnatTableIds>
          <SnatTableId>stb-wz9aq9mec6f843j45****</SnatTableId>
    </SnatTableIds>
    <ForwardTableIds>
          <ForwardTableId>ftb-wz9sl3znmxhy605f8****</ForwardTableId>
    </ForwardTableIds>
    <NatGatewayId>ngw-wz95lh0c2wj9b6r1z****</NatGatewayId>
</CreateNatGatewayResponse>

JSON format

{
	"BandwidthPackageIds":{
		"BandwidthPackageId":[]
	},
	"RequestId": "7C01CA72-73FD-4056-B16A-42E392D47625",
	"SnatTableIds":{
		"SnatTableId":[
			"stb-wz9aq9mec6f843j45****"
		]
	},
	"ForwardTableIds":{
		"ForwardTableId":[
			"ftb-wz9sl3znmxhy605f8****"
		]
	},
	"NatGatewayId": "ngw-wz95lh0c2wj9b6r1z****"
}

Errors

HTTP status code Error code Error message Description
400 InvalidVPCStatus vpc incorrect status. The VPC status is invalid.
404 InvalidRegionId.NotFound The specified RegionId does not exist in our records. The specified RegionId does not exist.
400 InvalidNatGatewayName.MalFormed NatGateway name is not valid. The specified name is invalid.
400 InvalidNatGatewayDescription.MalFormed NatGateway description is not valid. The specified description is invalid.
400 MissingParameter.BandwidthPackage only support one BandwidthPackage be created with NatGateway. You must specify a bandwidth package.
404 InvalidVpcId.NotFound Specified value of VpcId is not found in our record. The specified VPC does not exist.
400 MissingParameter Miss mandatory parameter. One or more mandatory parameters are missing.
404 InvalidZoneId.NotFound Specified value of ZoneId is not exists. The specified zone does not exist.
404 InvalidZoneId.NotFound Can not find ZoneId for allocated ip. The zone of the IP address is incorrect.
400 QuotaExceeded.BandwidthPackageIps The specified ipCount exceeded quota. The IP address quota has been reached.
400 InvalidParameter.Name.Malformed The specified Name is not valid. The specified name is invalid.
400 InvalidParameter.Description.Malformed The specified Description is not valid. The specified description is invalid.
400 ZONE_NO_AVAILABLE_IP The Zone have no available ip. There are no available IP addresses in this zone.
400 InvalidParameter.BandwidthPackage.n.ISP.ValueNotSupport The specified ISP of BandwidthPackage is not valid. The specified ISP is invalid.
400 InvalidNatGatewayId.NotFound The NatGatewayId not exist. The specified NatGatewayId does not exist.
400 VswitchStatusError The VSwitch is creating . The VSwitch is being created.
400 VpcStatusError The Vpc is creating . The VPC is being created.
400 InvalidParameter.Spec.ValueNotSupported The specified Spec is not valid. The specification is invalid.
400 Forbidden.CheckEntryRuleQuota Route entry quota rule check error. An error occurred while the route entry quota is being checked.

For a list of error codes, visit the API Error Center.