CreateNatGateway

Updated at:

Creates an enhanced Internet NAT gateway or a VPC NAT gateway.

Operation description

When you call this operation, take note of the following items:

  • When you create a NAT gateway for the first time, the system automatically creates a service-linked role named AliyunServiceRoleForNatgw and attaches an access policy named AliyunServiceRolePolicyForNatgw to the role. This grants the NAT gateway the permissions to access other cloud resources. For more information, see Service-linked roles.

  • After an enhanced Internet NAT gateway is created, the system automatically adds a route entry whose destination CIDR block is 0.0.0.0/0 and whose next hop is the NAT gateway to the route table of the VPC. This routes traffic to the NAT gateway.

  • CreateNatGateway is an asynchronous operation. The system first returns the instance ID of the NAT gateway (Internet NAT gateway or VPC NAT gateway), but the NAT gateway instance is not yet created, and the creation task is still running in the background. You can call DescribeNatGateways to query the status of the NAT gateway.

    • If the NAT gateway is in the Creating state, the NAT gateway is being created. In this state, you can only perform query operations.

    • If the NAT gateway is in the Available state, the NAT gateway is created.

It typically takes 1 to 3 minutes to create a NAT gateway.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

vpc:CreateNatGateway

create

*NatGateway

acs:vpc:{#regionId}:{#accountId}:natgateway/*

None None

Request parameters

Parameter

Type

Required

Description

Example

RegionId

string

Yes

The region ID of the NAT gateway.

You can call the DescribeRegions operation to query region IDs.

cn-hangzhou

VpcId

string

Yes

The ID of the VPC where you want to create the NAT gateway.

vpc-bp1di7uewzmtvfuq8****

Name

string

No

The name of the NAT gateway.

The name must be 2 to 128 characters in length. It must start with a letter or a Chinese character, and can contain digits, underscores (_), and hyphens (-).

If you do not specify this parameter, the system generates a default name for the NAT gateway.

fortest

Description

string

No

The description of the NAT gateway.

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

testnat

ClientToken

string

No

The client token that is used to ensure the idempotence of the request.

You can use the client to generate the value, but you must ensure that it is unique among different requests.

Note

If you do not specify this parameter, the system automatically uses the RequestId of the API request as the ClientToken. The RequestId of each API request may be different.

5A2CFF0E-5718-45B5-9D4D-70B3FF3898

Spec

string

No

Subscription Internet NAT gateways are no longer available for purchase. This parameter is no longer used.

Invalid parameter

InstanceChargeType

string

No

The billing method of the NAT gateway. Valid values:

PostPaid (default): pay-as-you-go.

For more information, see Internet NAT gateway billing and VPC NAT gateway billing.

PostPaid

PricingCycle

string

No

Subscription Internet NAT gateways are no longer available for purchase. This parameter is no longer used.

Invalid parameter

Duration

string

No

Subscription Internet NAT gateways are no longer available for purchase. This parameter is no longer used.

Invalid parameter

AutoPay

boolean

No

Subscription Internet NAT gateways are no longer available for purchase. This parameter is no longer used.

Important This parameter is deprecated.

false

VSwitchId

string

No

The ID of the vSwitch to which the NAT gateway belongs.

When you create a NAT gateway, you must specify the vSwitch to which the NAT gateway belongs. The system allocates an idle private IP address from the vSwitch to the NAT gateway.

  • If you want to create a NAT gateway in an existing vSwitch, make sure that the zone to which the vSwitch belongs supports NAT gateways and the vSwitch has available IP addresses.

  • If you have not created a vSwitch, create a vSwitch in a zone that supports NAT gateways, and then specify the vSwitch to which the NAT gateway belongs.

Note

You can call the ListEnhanhcedNatGatewayAvailableZones operation to query the zones that support NAT gateways, and call the DescribeVSwitches operation to query the available IP address count in a vSwitch.

vsw-bp1e3se98n9fq8hle****

NatType

string

No

The type of the NAT gateway. Set the value to Enhanced, which specifies an enhanced NAT gateway.

Enhanced

InternetChargeType

string

No

The metering method of the NAT gateway. Set the value to PayByLcu, which specifies pay-by-LCU.

PayByLcu

NetworkType

string

No

The type of the NAT gateway that you want to create. Valid values:

  • internet: Internet NAT gateway.

  • intranet: VPC NAT gateway.

internet

SecurityProtectionEnabled deprecated

boolean

No

Specifies whether to enable the firewall feature. Valid values:

  • false (default): disables the firewall feature.
    Important This parameter is deprecated.

false

IcmpReplyEnabled

boolean

No

Specifies whether to enable ICMP echo reply. Valid values:

  • true (default): enables ICMP echo reply.

  • false: disables ICMP echo reply.

true

PrivateLinkEnabled

boolean

No

Specifies whether to enable PrivateLink. Valid values:

  • true: enables PrivateLink.

  • false (default): disables PrivateLink.

false

EipBindMode

string

No

The EIP binding mode of the NAT gateway. Valid values:

  • MULTI_BINDED (default): multi-EIP NIC-visible mode.

  • NAT: NAT mode, which is compatible with IPv4 gateways.
    Note

    When the EIP binding mode of the NAT gateway is set to NAT mode, the EIP occupies a private IP address of the vSwitch to which the NAT gateway belongs. Make sure that the vSwitch has sufficient private IP addresses. If the vSwitch to which the NAT gateway belongs does not have available idle private IP addresses, you cannot bind new EIPs. When the EIP binding mode of the NAT gateway is set to NAT mode, the NAT gateway supports a maximum of 50 EIPs.

MULTI_BINDED

Tag

array<object>

No

The list of tags.

MULTI_BINDED

object

No

Key

string

No

The tag key. You can use the Tag.N.Key format when you call API operations. Valid values of N: 1 to 20. If you specify this parameter, it cannot be an empty string. The tag key can be up to 128 characters in length. It cannot start with aliyun or acs:, and cannot contain http:// or https://.

TestKey

Value

string

No

The tag value. You can use the Tag.N.Value format when you call API operations. Valid values of N: 1 to 20. If you specify this parameter, it cannot be an empty string. The tag value can be up to 128 characters in length. It cannot start with aliyun or acs:, and cannot contain http:// or https://.

TestValue

AccessMode

object

No

The access mode for reverse access to the VPC NAT gateway.

MULTI_BINDED

ModeValue

string

No

The access mode. Valid values:

  • route: route mode.

  • tunnel: tunnel mode.

Note

When this field is specified, the PrivateLinkEnabled field must be set to true.

route

TunnelType

string

No

The tunnel mode type. Valid values:

  • geneve: Geneve.

Note

This value is valid only when the access mode is set to tunnel mode.

geneve

NatIp

string

No

The private IP address that is allocated to the NAT gateway. Use an unallocated IP address in the vSwitch CIDR block of the NAT gateway. If this parameter is left empty, an IP address is randomly allocated.

Note

This parameter takes effect only for VPC NAT gateways.

192.168.0.2

Ipv4Prefix

string

No

The IP prefix CIDR block that is used to create NAT IP addresses in batches. Use an unallocated reserved CIDR block in the vSwitch to which the NAT gateway belongs.

Note

This parameter takes effect only for VPC NAT gateways.

192.168.0.0/28

AvailabilityMode

string

No

The disaster recovery type of the NAT gateway. Valid values:

  • CrossAZ: cross-zone disaster recovery.

  • SingleAZ: single-zone disaster recovery.

CrossAZ

Response elements

Element

Type

Description

Example

object

The response struct.

NatGatewayId

string

The instance ID of the created NAT gateway.

ngw-112za33e4****

RequestId

string

The request ID.

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

ForwardTableIds

object

ForwardTableId

array

The DNAT table.

string

The DNAT table.

ftb-11tc6xgmv****

SnatTableIds

object

SnatTableId

array

The SNAT table.

string

The SNAT table.

stb-SnatTableIds****

FullNatTableIds

object

FullNatTableId

array

The FULLNAT table.

string

The FULLNAT table.

fulltb-gw88z7hhlv43rmb26****

Examples

Success response

JSON format

{
  "NatGatewayId": "ngw-112za33e4****",
  "RequestId": "2315DEB7-5E92-423A-91F7-4C1EC9AD97C3",
  "ForwardTableIds": {
    "ForwardTableId": [
      "ftb-11tc6xgmv****"
    ]
  },
  "SnatTableIds": {
    "SnatTableId": [
      "stb-SnatTableIds****"
    ]
  },
  "FullNatTableIds": {
    "FullNatTableId": [
      "fulltb-gw88z7hhlv43rmb26****"
    ]
  }
}

Error codes

HTTP status code

Error code

Error message

Description

400 Forbidden.NatPayBySpec Pay-by-specification NAT is no longer supported. Newly purchased pay-as-you-go NAT gateways only support the pay-by-CU metering method. Pay-by-specification NAT gateways are no longer available for purchase. Set InternetChargeType to PayByLcu.
400 DependencyViolation.FullNatEntry The specified resource of %s depends on %s, so the operation cannot be completed.
400 UnsupportedFeature.InternetChargeType The feature of InternetChargeType is not supported.
400 InvalidVPCStatus vpc incorrect status.
400 InvalidNatGatewayName.MalFormed NatGateway name is not valid.
400 InvalidNatGatewayDescription.MalFormed NatGateway description is not valid.
400 MissingParameter.BandwidthPackage only support one BandwidthPackage be created with NatGateway.
400 OperationDenied The user cannot allow to create natgw, please call PD to authorize
400 RouterEntryConflict.Duplicated A route entry already exists, which CIDR is '0.0.0.0/0'
400 MissingParameter Miss mandatory parameter.
400 QuotaExceeded.BandwidthPackageIps The specified ipCount exceeded quota. The number of IP addresses has reached the upper limit. Request a quota increase on the Quota Management page.
400 AllocateIpFailed Alloc bandwidthPackage ips failed, maybe no available ip.
400 InvalidParameter.Name.Malformed The specified Name is not valid.
400 InvalidParameter.Description.Malformed The specified Description is not valid.
400 ZONE_NO_AVAILABLE_IP The Zone have no available ip.
400 ParameterIllegal ipCount,bandwidth parameter invalid
400 InvalidParameter.BandwidthPackage.n.ISP.ValueNotSupport The specified ISP of BandwidthPackage is not valid.
400 InvalidNatGatewayId.NotFound The NatGatewayId not exist.
400 VpcStatusError The Vpc is creating .
400 InvalidParameter.Spec.ValueNotSupported The specified Spec is not valid.
400 TaskConflict The operation is too frequent, TaskConflict. The system is unavailable. Try again later.
400 COMMODITY.INVALID_COMPONENT The instance component is invalid. The instance component is invalid.
400 CreateNatGateway.RouteConflict.DynamicRoute Route conflict exists in routing table.
400 OperationUnsupported.MultiNatGateway More than one natGateway per vpc is unsupported.
400 Forbidden.CheckEntryRuleQuota Route entry quota rule check error.
400 OperationFailed.UnpaidBillsExist The account has unpaid bills. Please pay your overdue bill first. This account has unpaid orders.
400 IncorrectStatus.RouteEntry Specified routeEntry status error.
400 OperationFailed.RiskControl Risk control check failed. The error message returned because your payment method has security risks. Click the link for verification in your email or console message and submit your order after verification.
400 OperationFailed.TokenVerfiy Token verify failed.
400 IllegalParam.Name The specified Name is invalid, shorter than 2 characters.
400 OperationFailed.EnhancedQuotaExceed Enhanced nat gateway per vpc quota is exceeded The operation failed because the number of enhanced NAT gateways in the current VPC exceeds the limit.
400 NoPermission.CreateServiceLinkedRole You are not authorized to create service linked role
400 OperationFailed.EnhancedInventoryNotEnough Operation failed because inventory is not enough.
400 OperationFailed.VswNotBelongToVpc Operation failed because the specified VSwitch is not bound to the same VPC with NAT gateway. The vSwitch and NAT gateway do not belong to the same VPC.
400 OperationFailed.EnhancedUserIsUnAuthorized Operation failed because the user is not authorized to create an enhanced NAT gateway. Operation failed because the user is not authorized to create an enhanced NAT gateway.
400 OperationUnsupported.PrePaidPyByLcu The operation failed because the subscription NAT gateway does not support the pay-by-LCU billing method. The operation failed because the subscription NAT gateway does not support the pay-by-LCU billing method.
400 OperationFailed.NormalInventoryNotEnough Standard NAT gateways are no longer offered. You can create enhanced NAT gateways and set the correct natType.
400 OperationFailed.VSwitchNoAvailableIp Operation failed because the specified vswitch does not have availabe ip.
400 UnsupportedFeature.IcmpReplyEnabled The feature of IcmpReplyEnabled is not supported. The value of IcmpReplyEnabled cannot be modified.
400 UnsupportedFeature.SecurityProtectionEnabled The feature of SecurityProtectionEnabled is not supported.
400 OperationFailed.RegionConvert Operation failed because do not find region info.
400 UnsupportedFeature.VpcNat The feature of VpcNat is not supported.
400 InvalidVSWITCHID.NotFound The specified resource of %s is not found.
400 Forbidden.OperateShareResource Operate share resource is forbidden.
400 IncorrectStatus.VSWITCH The status of VSWITCH is incorrect. The virtual switch is in an abnormal state.
400 OperationFailed.VpcNatGatewayInventoryNotEnough The operation is failed because of inventory is not enough.
400 OperationFailed.VpcNatGatewayCheckInventory The operation is failed because of check inventory result is unexpected
400 ExclusiveParam.%sAnd%s The param of %s and %s are mutually exclusive. You cannot specify %s and %s at the same time.
400 SecurityGroupType.NotSupported The specified security group type is not supported. The security group is already hosted and cannot be used.
400 SecurityGroup.NotExist The specified security group is not exist. The security group does not exist in this VPC.
400 OperationFailed.ContainForbiddenLabel There is a label that prohibits ordering, please contact your distributor for processing. There is a label that prohibits ordering, please contact your distributor for processing.
400 OperationDenied.PrePaidInstance The operation is not allowed because prepaid instance is no longer supported. Prepaid instance is no longer supported.
400 UnsupportedFeature.Geneve The feature of Geneve is not supported. The feature of Geneve is not supported.
400 OperationFailed.NoAvailableResource The Zone have no available resource. No resources are available in the region.
400 ExclusiveParam.AccessModeValueAndAccessTunnelType The specified param AccessModeValue and AccessTunnelType are mutually exclusive. The specified input AccessMode.ModeValue and AccessMode.TunnelType conflict
400 ExclusiveParam.PrivateLinkModeAndAccessMode The specified param PrivateLinkMode and AccessMode are mutually exclusive. The specified input PrivateLinkMode conflicts with the AccessMode.
400 ExclusiveParam.PrivateLinkEnabledAndAccessMode The specified paramPrivateLinkEnabled and AccessMode are mutually exclusive. The specified input PrivateLinkEnabled conflicts with the AccessMode.
400 UnsupportedFeature.AccessModeValue The feature of AccessMode.ModeValue(%s) is not supported. This operation is not supported for the VPC NAT AccessMode.ModeValue attribute
400 IllegalParam.AccessTunnelType The request parameter AccessMode.TunnelType is illegal. The request parameter AccessMode.TunnelType is illegal.
400 IllegalParam.AccessModeValue The request parameter AccessMode.ModeValue is illegal. The request parameter AccessMode.ModeValue is illegal.
400 OperationFailed.VSwitchStatusError The vSwitch is creating . The vSwitch is being created.
400 UnsupportedFeature.PrivateLinkMode The feature of %s is not supported. The feature of reverse access is not supported.
400 OperationFailed.EcsNetworkInterfaceQuotaNotSatisfy ECS network interface quota is not satisfy. The ECS ENI quota does not meet the requirements.
400 OperationFailed.NoNameAuthentication You have not passed the real name authentication and do not meet the purchase conditions. Please log in to the user center for real-name authentication. You have not passed the real name authentication and do not meet the purchase conditions. Please log in to the user center for real-name authentication.
400 Mismatch.NatIpAndNatIpCidr The %s and %s are mismatched. The specified %s and %s do not match.
400 Mismatch.Ipv4PrefixAndNatIpCidr The %s and %s are mismatched. The Ipv4Prefix and NatIpCidr are mismatched.
400 ResourceAlreadyExist.NatIp The specified resource of NatIp has already exist. Configured NatIp already exists
400 Mismatch.Ipv4PrefixAndCidrReservations The %s and %s are mismatched. The reserved network segments of the Ipv4Prefix and VSwitch do not match.
400 ResourceAlreadyAssociated.Ipv4Prefix %s is already associated. Ipv4Prefix have been allocated.
400 ResourceNotEnough.Ipv4Prefix The resource of %s is not enough. Insufficient Ipv4Prefix resources.
400 ResourceNotFound.Ipv4Prefix The resource of s% is not found.
400 ResourceAlreadyAssociated.NatIp The resource of %s was already associated. NatIp resources have been allocated.
400 ResourceNotEnough.NatIp The specified resource of NatIp is not enough. Insufficient IP addresses in the specified CIDR block.
400 ResourceNotFound.NatIp The specified resource of %s is not found. The specified NatIp parameter is not found.
400 IllegalParam.Ipv4Prefix The param of %s is illegal, must be /28 network segment. The parameter Ipv4Prefix is invalid and must be/28 network segment.
400 IllegalParam.NatIp The param of %s is illegal. The parameter NatIp is illegal.
400 OperationUnsupported.EnhancedRegion Region not support. The current region is temporarily not supported.
400 IncorrectStatus.RouteTableStatus The route table status is invaild. Please try again later. The routing table status does not support this operation. Please try again later.
400 OperationUnsupported.User The current user does not support this operation. The current user does not support this operation.
400 OperationUnsupported.EnhancedCURegion Operation failed because of this region not unsupported. Operation failed due to unsupported pay-as-you-go region
400 OrderError.NoAvailablePaymentMethod Order payment parameter is not available. Order error. The payment type parameter is not available.
400 OrderError.BasicInfoUncompleted Order basic parameter is not completed. Order error, basic parameter information incomplete.
400 OperationUnsupported.Region Operation unsupport this region parameter. This operation does not support the region parameter
400 InvalidParameter.SingleZone Operation failed because current user not support create single zone nat. current user is not allowed to create a single az nat
500 OrderError.NatGateway The Account failed to create order.
500 OperationFailed.AccessTunnelId AccessTunnelId param do operation failed. VPC NAT failed to generate tunnel ID. Try again later
500 OperationFailed.EnhancedCheckInventory The NAT gateway in the current zone is not in service, or the resource inventory is insufficient. The NAT gateway in the current zone is not in service, or the resource inventory is insufficient.
404 InvalidRegionId.NotFound The specified RegionId does not exist in our records.
404 InvalidVpcId.NotFound Specified value of VpcId is not found in our record. The VPC does not exist. Check whether the specified VPC is valid.
404 InvalidZoneId.NotFound Specified value of ZoneId is not exists.
404 VPC_ONLY_CAN_CREATE_ONE_NAT_GATEWAY NatGateway in one vpc support only one.
404 OperationFailed.CrateEntryTimeOut Operation failed because create custom routeEntry timeout.
404 Forbidden.CreateSpecialSpecNatGateway You are not authorized to create special spec nat gateway.
404 UnsupportedZoneForFwNat The zone is unsupported for FW NAT. The zone does not support protected NAT gateways.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.