Create a NAT Gateway.

Note the following before creating a NAT Gateway:

  • 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 need to delete the router entry. Otherwise, the NAT Gateway cannot be created.

Debug

By using API Explorer, you can easily debug APIs, automatically generate SDK code examples, and quickly search for APIs. API Explorer can help reduce possible difficulty with using cloud APIs. We recommend that you use API Explorer.

Request parameters

Parameter Type Required? Example value Description
Action String Yes CreateNatGateway

The action to perform. Valid value:

CreateNatGateway

RegionId String Yes cn-hangzhou

The region to which the NAT Gateway belongs.

To obtain the region ID, call DescribeRegions.

VpcId String Yes vpc-bp1di7uewzmtvfuq8ufpv

The ID of the VPC to be used.

BandwidthPackage.n.Bandwidth String No 5

The bandwidth of the NAT bandwidth package (n). Valid value: [5,5000]

Note This API can be called only if you purchased a NAT bandwidth package before January 26, 2018. If your account does not have a NAT bandwidth package purchased before January 26, 2018, you need to attach an EIP.
BandwidthPackage.N.ISP String No BGP

The ISP type of the shared bandwidth package (n). Default value: BGP (multiple lines).

BandwidthPackage.n.IpCount String No 5

The number of public IP addresses in the shared bandwidth package. Valid value: [1,50]. n represents the n-th bandwidth package. Valid values: [1,4].

Note This API can be called only if you purchased a NAT bandwidth package before January 26, 2018. If your account did not include a NAT bandwidth package before January 26, 2018, attach an EIP.
BandwidthPackage.n.Zone String No cn-hangzhou-b

The zone of the shared bandwidth package (n). The system randomly allocates a zone if this parameter is not specified.

If the NAT bandwidth package and the backend ECS instance are not in the same zone, the latency of the connection between them is unchanged; if they are in the same zone, the latency can be reduced.

Note This API can be called only if you purchased a NAT bandwidth package before January 26, 2018. If your account does not have a NAT bandwidth package before January 26, 2018, you need to attach an EIP.
ClientToken String No shefffxxddjehfh123

A client token used to guarantee the idempotence of requests.

This parameter value is generated by the client and must be unique. It cannot exceed 64 ASCII characters.

Description String No testnat

The description of the NAT Gateway.

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

Name String No fortest

The name of the NAT Gateway.

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

If this parameter is not specified, the gateway ID is used by default.

Spec String No small
The specification of the NAT Gateway.  Valid values:
  • Small (default): small

  • Middle: medium

  • Large: large

  • Xlarge. 1: super large

Response parameters

Parameter Type Example value Description
NatGatewayId String ngw-112za33e4

The ID of the NAT Gateway.

The ID is generated by the system and is globally unique.

ForwardTableIds ftb-11tc6xgmv

A list of forwarding tables.

BandwidthPackageIds bwp-11odxu2k7

A list of shared bandwidth packages.

RequestId String 2315DEB7-5E92-423A-91F7-4C1EC9AD97C3

The ID of the request.

SnatTableIds stb-SnatTableIds

The ID of the SNAT table.

Examples

Request example


https://vpc.aliyuncs.com/?Action=CreateNatGateway
&RegionId=cn-hangzhou
&VpcId= vpc-bp1di7uewzmtvfuq8ufpv
&<CommonParameters>
Response example
  • XML format

    <CreateNatGatewayResponse>
      <BandwidthPackageIds>bwp-**************</BandwidthPackageIds>
      <forwardTableIds>ftb-**************</forwardTableIds>
      <natGatewayId>ngw-**************</natGatewayId>
      <snatTableIds>stb-**************</snatTableIds>
      <RequestId>E43E51F2-344F-4685-8DF5-30EB298CFA81</RequestId>
    </CreateNatGatewayResponse>
    
  • JSON format

    {
    	"BandwidthPackageIds":[
    		"bwp-**************"
    	],
    	"snatTableIds":[
    		"stb-**************"
    	],
    	"natGatewayId":"ngw-**************",
    	"RequestId":"E43E51F2-344F-4685-8DF5-30EB298CFA81",
    	"forwardTableIds":[
    		"ftb-**************"
    	]
    }
    

Error codes

HTTP 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 region ID does not exist.
400 MissingParameter.BandwidthPackage only support one BandwidthPackage be created with NatGateway. At least one shared bandwidth package must be specified.
400 MissingParameter Miss mandatory parameter. Required 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. To increase the quota, open a ticket.
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 ISP of the shared bandwidth package is invalid.
400 InvalidNatGatewayId.NotFound The NatGatewayId not exist. The specified NatGatewayId is invalid.
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.

View the error codes of the product