Menu
Amazon Elastic Compute Cloud
API Reference (API Version 2016-11-15)

CreateNatGateway

Creates a NAT gateway in the specified subnet. A NAT gateway can be used to enable instances in a private subnet to connect to the Internet. This action creates a network interface in the specified subnet with a private IP address from the IP address range of the subnet. For more information, see NAT Gateways in the Amazon Virtual Private Cloud User Guide.

Request Parameters

The following parameters are for this specific action. For more information about required and optional parameters that are common to all actions, see Common Query Parameters.

AllocationId

The allocation ID of an Elastic IP address to associate with the NAT gateway. If the Elastic IP address is associated with another resource, you must first disassociate it.

Type: String

Required: Yes

ClientToken

Unique, case-sensitive identifier you provide to ensure the idempotency of the request. For more information, see How to Ensure Idempotency.

Constraint: Maximum 64 ASCII characters.

Type: String

Required: No

SubnetId

The subnet in which to create the NAT gateway.

Type: String

Required: Yes

Response Elements

The following elements are returned by the service.

clientToken

Unique, case-sensitive identifier to ensure the idempotency of the request. Only returned if a client token was provided in the request.

Type: String

natGateway

Information about the NAT gateway.

Type: NatGateway object

requestId

The ID of the request.

Type: String

Errors

For information about the errors that are common to all actions, see Common Client Errors.

Example

Example

This example creates a NAT gateway in subnet subnet-1a2b3c4d and associates the Elastic IP address (with the allocation ID eipalloc-37fc1a52) to the NAT gateway.

Sample Request

https://ec2.amazonaws.com/?Action=CreateNatGateway
&SubnetId=subnet-1a2b3c4d
&AllocationId=eipalloc-37fc1a52
&AUTHPARAMS

Sample Response

<CreateNatGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
    <requestId>1b74dc5c-bcda-403f-867d-example</requestId>
    <natGateway>
        <subnetId>subnet-1a2b3c4d</subnetId>
        <natGatewayAddressSet>
            <item>
                <allocationId>eipalloc-37fc1a52</allocationId>
            </item>
        </natGatewayAddressSet>
        <createTime>2015-11-25T14:00:55.416Z</createTime>
        <vpcId>vpc-4e20d42b</vpcId>
        <natGatewayId>nat-04e77a5e9c34432f9</natGatewayId>
        <state>pending</state>
    </natGateway>
</CreateNatGatewayResponse>

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: