# CreateNatGateway

## 1. 接口描述

本接口(CreateNatGateway)用于创建NAT网关。

{% hint style="info" %}
**注意事项**

* 本接口为异步接口，接口成功返回后，可使用 [DescribeNatGateways](https://docs.console.zenlayer.com/api-reference/cn/compute/zec/nat-gateway/describenatgateways) 接口查询NAT网关的状态。其中状态为`RUNNING`则代表创建成功。
* 只支持后付费NAT网关创建。
  {% endhint %}

## 2. 请求参数

以下请求参数列表仅列出了接口中需要的请求参数

| 参数名称            | 必选 | 类型                                                                                                        | 描述                                                             |
| --------------- | -- | --------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| regionId        | 是  | String                                                                                                    | 区域节点ID。                                                        |
| vpcId           | 是  | String                                                                                                    | NAT网关所属的VPC网络ID。                                               |
| name            | 是  | String                                                                                                    | <p>NAT网关的名称。</p><p>长度为2～63个字符。</p>                             |
| subnetIds       | 否  | Array of String                                                                                           | <p>NAT网关所属的Subnet子网ID集合。</p><p>如果未指定，则指定区域的所有子网将自动关联NAT网关。</p> |
| securityGroupId | 否  | String                                                                                                    | <p>安全组ID。</p><p>如果未指定，则指定VPC所属的安全组ID。</p>                      |
| resourceGroupId | 否  | String                                                                                                    | <p>资源组ID。</p><p>如果不指定，则会创建在默认资源组。</p>                          |
| tags            | 否  | [TagAssociation](https://docs.console.zenlayer.com/api-reference/cn/compute/datastructure#tagassociation) | <p>创建NAT网关时关联的标签。</p><p>注意：·关联<code>标签键</code>不能重复。</p>        |

## 3. 响应结果

| 参数名称         | 类型     | 描述                                                       |
| ------------ | ------ | -------------------------------------------------------- |
| requestId    | String | <p>唯一请求 ID。</p><p>每次请求都会返回。定位问题时需要提供该次请求的 requestId。</p> |
| orderNumber  | String | 下单编号。                                                    |
| natGatewayId | String | NAT网关唯一ID。                                               |

## 4. 代码示例

{% tabs %}
{% tab title="示例" %}
**1. 创建一个NAT网关。**

```json
POST /api/v2/zec HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: CreateNatGateway
<Common Request Params>

Request：
{
    "regionId": "asia-east-1",
    "vpcId": "<vpcId>",
    "name": "name",
    "subnetIds": ["<subnet>", "<subnet>"],
    "resourceGroupId": "<resourceGroupId>"
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "orderNumber": "<orderNumber>",
    "natGatewayId": "<natGatewayId>"
  }
}
```

{% endtab %}
{% endtabs %}

## 5. 开发者工具

Zenlayer Cloud API 2.0 提供了配套的[开发工具集（SDK）](https://docs.console.zenlayer.com/api-reference/cn/api-introduction/toolkit)，未来会陆续支持更多开发语言，方便快速接入和使用Zenlayer的产品和服务。

## 6. 错误码

下面包含业务逻辑中遇到的错误码，其他错误码见[公共错误码](https://docs.console.zenlayer.com/api-reference/cn/api-introduction/instruction/commonerrorcode)

| HTTP状态码 | 错误码                                           | 说明              |
| ------- | --------------------------------------------- | --------------- |
| 404     | INVALID\_REGION\_NOT\_FOUND                   | 指定的可用区不存在。      |
| 404     | INVALID\_VPC\_NOT\_FOUND                      | VPC不存在。         |
| 404     | INVALID\_SUBNET\_NOT\_FOUND                   | 子网不存在。          |
| 400     | OPERATION\_DENIED\_NAT\_SUBNET\_CONFLICT      | NAT的Subnet配置冲突。 |
| 400     | OPERATION\_DENIED\_SUBNET\_STATUS             | Subnet状态不可用。    |
| 400     | OPERATION\_DENIED\_SUBNET\_NAT\_CONFLICT      | Subnet存在NAT网关。  |
| 404     | INVALID\_EIP\_NOT\_FOUND                      | EIP不存在。         |
| 400     | OPERATION\_DENIED\_EIP\_IS\_NOT\_UN\_ASSIGN   | EIP状态未解绑。       |
| 400     | OPERATION\_DENIED\_SNAT\_ENTRY\_COUNT\_LIMIT  | SNAT规则数量限制。     |
| 400     | OPERATION\_DENIED\_DNAT\_ENTRY\_COUNT\_LIMIT  | DNAT规则数量限制。     |
| 400     | OPERATION\_DENIED\_SUBNET\_TYPE\_NOT\_SUPPORT | 子网堆栈类型不支持。      |
| 404     | INVALID\_SECURITY\_GROUP\_NOT\_FOUND          | 安全组不存在。         |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/api-reference/cn/compute/zec/nat-gateway/createnatgateway.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
