All Products
Search
Document Center

VPN Gateway:CreateVpnGateway

Last Updated:Jun 19, 2026

Creates a VPN gateway by calling the CreateVpnGateway operation.

Operation description

  • Before you create a VPN gateway, we recommend that you familiarize yourself with the limits of VPN gateways. For more information, see VPN gateway limits.

  • VPN gateway instances in some regions support only dual-tunnel mode IPsec-VPN connections by default. When you call the CreateVpnGateway operation to create a VPN gateway instance in these regions, you must specify the VSwitchId and DisasterRecoveryVSwitchId parameters in addition to the required parameters. For information about the regions and zones that support dual-tunnel mode IPsec-VPN connections, see Upgrade an IPsec-VPN connection to dual-tunnel mode.

  • CreateVpnGateway is an asynchronous operation. After you call this operation, the system returns an instance ID, but the VPN gateway is not yet created. The creation task is still running in the background. You can call DescribeVpnGateway to query the creation status of the VPN gateway:

    • If the VPN gateway is in the provisioning state, the VPN gateway is being created.

    • If the VPN gateway is in the active state, the VPN gateway is created.

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:CreateVpnGateway

create

*VpnGateway

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

None None

Request parameters

Parameter

Type

Required

Description

Example

RegionId

string

Yes

The region ID of the VPN gateway. You can call the DescribeRegions operation to query the region ID.

cn-hangzhou

Name

string

No

The name of the VPN gateway. The default value is the ID of the VPN gateway.

The name must be 2 to 100 characters in length. It cannot start with http:// or https://. It must start with an uppercase or lowercase letter and can contain uppercase and lowercase letters, digits, underscores (_), hyphens (-), and periods (.). Other special characters are not supported.

MYVPN

VpcId

string

Yes

The ID of the VPC-connected instance to which the VPN gateway belongs.

vpc-bp1ub1yt9cvakoelj****

InstanceChargeType

string

No

The billing method of the VPN gateway. Set the value to POSTPAY, which specifies the pay-as-you-go billing method.

中国站示例值:PREPAY,国际站示例值:POSTPAY

Period

integer

No

The subscription duration. Unit: months. Valid values: 1 to 9, 12, 24, and 36.

1

AutoPay

boolean

No

Specifies whether to automatically pay the bill for the VPN gateway. Valid values:

  • true: automatically pays the bill for the VPN gateway.

  • false (default): does not automatically pay the bill for the VPN gateway.

Note

To successfully create a VPN gateway instance, enable automatic payment. If you disable automatic payment, you must manually pay the bill to create the VPN gateway instance.

false

Bandwidth

integer

Yes

The bandwidth specification of the VPN gateway. Unit: Mbit/s.

  • If you want to create a public VPN gateway, valid values are 10, 100, 200, 500, and 1000.

  • If you want to create a private VPN gateway, valid values are 200 and 1000.

Note

The maximum bandwidth specification supported by VPN gateways in some regions is 500 Mbit/s. For more information, see VPN gateway limits.

5

EnableIpsec

boolean

No

Specifies whether to enable the IPsec-VPN feature. Valid values:

  • true (default): enables the IPsec-VPN feature.

  • false: disables the IPsec-VPN feature.

true

EnableSsl

boolean

No

Specifies whether to enable the SSL-VPN feature. Valid values:

  • true: enables the SSL-VPN feature.

  • false (default): disables the SSL-VPN feature.

false

SslConnections

integer

No

The maximum number of clients that can be simultaneously connected. Valid values: 5 (default), 10, 20, 50, 100, 200, 500, and 1000.

5

VSwitchId

string

No

The vSwitch associated with the VPN gateway instance.

  • In regions that support dual-tunnel mode IPsec-VPN connections, this parameter is required. You must specify a vSwitch and also specify the DisasterRecoveryVSwitchId parameter.

  • In regions that support only single-tunnel mode IPsec-VPN connections, if you do not specify a vSwitch, the system automatically selects a vSwitch from the VPC.

vsw-bp1j5miw2bae9s2vt****

VpnType

string

No

The type of the VPN gateway. Valid values:

  • Normal (default): standard.

  • .

Normal

ClientToken

string

No

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

You can use the client to generate the token, but you must make sure that the token is unique among different requests. The client token can contain only ASCII characters.

Note

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

02fb3da4****

NetworkType

string

No

The network type of the VPN gateway. Valid values:

  • public (default): public VPN gateway.

  • private: private VPN gateway.

public

DisasterRecoveryVSwitchId

string

No

The second vSwitch associated with the VPN VPC-connected instance.

  • If the current region supports dual-tunnel mode IPsec-VPN connections, this parameter is required.

  • You must specify two vSwitches in different zones within the VPC associated with the VPN VPC-connected instance to implement zone-level disaster recovery for IPsec-VPN connections.

  • For regions that support only one zone, zone-level disaster recovery is not supported. Specify two different vSwitches in the same zone to achieve high availability for IPsec-VPN connections. You can also specify the same vSwitch.

For information about the regions and zones that support dual-tunnel mode IPsec-VPN connections, see Upgrade an IPsec-VPN connection to dual-tunnel mode.

vsw-p0wiz7obm0tbimu4r****

ResourceGroupId

string

No

The ID of the resource group to which the VPN gateway belongs.

  • You can call the ListResourceGroups operation to query resource group IDs.

  • If you do not specify a resource group ID, the VPN gateway belongs to the default resource group after it is created.

  • After the VPN gateway is created, if you create SSL servers, SSL client certificates, IPsec servers, or IPsec-VPN connections (when the IPsec-VPN connection is bindded to the VPN gateway) under the VPN gateway, these resources belong to the same resource group as the VPN gateway and cannot be modified individually.

    If you change the resource group of the VPN gateway, the resource group of the preceding resources is also changed.

rg-acfmzs372yg****

Response elements

Element

Type

Description

Example

object

The response parameters.

VpnGatewayId

string

The instance ID of the VPN gateway.

vpn-uf68lxhgr7ftbqr3p****

RequestId

string

The request ID.

EB2C156A-41F8-49CC-A756-D55AFC8BFD69

Name

string

The name of the VPN gateway.

MYVPN

OrderId

integer

The order ID.

If you did not enable automatic payment for the VPN gateway bill, go to Expenses and Costs to complete the payment..

208240895400460

Examples

Success response

JSON format

{
  "VpnGatewayId": "vpn-uf68lxhgr7ftbqr3p****",
  "RequestId": "EB2C156A-41F8-49CC-A756-D55AFC8BFD69",
  "Name": "MYVPN",
  "OrderId": 208240895400460
}

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidVpcId.NotFound The specified VPC id does not exist in our records.
400 InvalidName The specified value of Name not supported.
400 InvalidSpec.NotFound The specified Spec does not exist in our records.
400 InvalidPeriod The specified period is not valid
400 ChargeType.NotSupport The specified charge type is not support.
400 InventoryNotEnough The inventory is not enough.
400 UnnecessarySslConnection The SSL connection is unnecessary for ssl vpn disabled.
400 InvalidVpnEnable Either IPsec or SSL VPN must be set enable.
400 Resource.QuotaFull The quota of resource is full
400 InvalidVSwitchId.NotFound The specified vswitchId is not found.
400 OperationFailed.InventoryNotEnough No enough available resource. Try another vswitch with different available zone.
400 Forbidden.OperateShareResource Operating shared resources is forbidden.
400 OperationFailed.IpNotEnough Operation failed because private ip address of the virtual switch is not enough.
400 Forbidden.NoSLRPermission User not authorized to create service linked role.
400 OperationFailed.VSwitchConflict The vswitch can't create vpn. Try another vswitch.
400 OperationFailed.AzNotSupport Current available zone can't create vpn. Try another vswitch with different available zone.
400 OperationFailed.NetworkTypeNotMatch Create NationalStandard vpn with private networkType is unsupported.
400 OperationFailed.SslNotSupport Enable ssl vpn with private networkType is unsupported. You cannot enable the SSL feature for a private VPN gateway.
400 Forbidden.TagKey.Duplicated The specified tag key already exists. The tag resources are duplicate.
400 SizeLimitExceeded.TagNum The maximum number of tags is exceeded. The number of tags has reached the upper limit.
400 InvalidParameter.TagValue The specified parameter TagValue is invalid. The error message returned because the specified tag value is invalid.
400 InvalidParameter.TagKey The specified parameter TagKey is invalid. The error message returned because the specified tag key is invalid.
400 Duplicated.TagKey The specified parameter TagKey is duplicated. The error message returned because the specified tag key already exists.
400 InternalError The request processing has failed due to some unknown error, exception or failure.
400 InvalidVSwitchId.SecondVswitchNotSupport The available zone of vswitch2 not supported. The zone of the secondary vSwitch does not support the feature.
400 InvalidVSwitchId.FirstVswitchNotSupport The available zone of vswitch1 not supported. The zone where the primary vSwitch is located is not supported.
400 InvalidVSwitchId.VswitchIdShouldDifferent The VSwitch ids should be different. The primary zone cannot be the same as the secondary zone.
400 InvalidVSwitchId.FirstVswitchIpNotEnough The ip of vswitch1 not enough. Insufficient number of available IPs in primary vSwitch.
400 InvalidVSwitchId.SecondVswitchIpNotEnough The ip of vswitch2 not enough. Insufficient IP addresses are available in the standby vSwitch.
400 InvalidVSwitchId.ZoneIdShouldDifferent Two vSwitches should belong to different Availability Zones. When you create a dual-tunnel VPN gateway, the two vSwitches that you specify must belong to different zones.
404 InvalidRegionId.NotFound The specified region is not found during access authentication. The specified area is not found during authentication.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.