Skip to content

EC2  >  Operations  >  create_nat_gateway

create_nat_gateway

Operation

create_nat_gateway async

create_nat_gateway(input: CreateNatGatewayInput, plugins: list[Plugin] | None = None) -> CreateNatGatewayOutput

Creates a NAT gateway in the specified subnet. This action creates a network interface in the specified subnet with a private IP address from the IP address range of the subnet. You can create either a public NAT gateway or a private NAT gateway.

With a public NAT gateway, internet-bound traffic from a private subnet can be routed to the NAT gateway, so that instances in a private subnet can connect to the internet.

With a private NAT gateway, private communication is routed across VPCs and on-premises networks through a transit gateway or virtual private gateway. Common use cases include running large workloads behind a small pool of allowlisted IPv4 addresses, preserving private IPv4 addresses, and communicating between overlapping networks.

For more information, see NAT gateways in the Amazon VPC User Guide.

Warning

When you create a public NAT gateway and assign it an EIP or secondary EIPs, the network border group of the EIPs must match the network border group of the Availability Zone (AZ) that the public NAT gateway is in. If it's not the same, the NAT gateway will fail to launch. You can see the network border group for the subnet's AZ by viewing the details of the subnet. Similarly, you can view the network border group of an EIP by viewing the details of the EIP address. For more information about network border groups and EIPs, see Allocate an Elastic IP address in the Amazon VPC User Guide.

Parameters:

Name Type Description Default
input CreateNatGatewayInput

An instance of CreateNatGatewayInput.

required
plugins list[Plugin] | None

A list of callables that modify the configuration dynamically. Changes made by these plugins only apply for the duration of the operation execution and will not affect any other operation invocations.

None

Returns:

Type Description
CreateNatGatewayOutput

An instance of CreateNatGatewayOutput.

Input

CreateNatGatewayInput dataclass

Bases: _SerdeShape

Dataclass for CreateNatGatewayInput structure.

Attributes

allocation_id class-attribute instance-attribute
allocation_id: str | None = ...

[Public NAT gateways only] The allocation ID of an Elastic IP address to associate with the NAT gateway. You cannot specify an Elastic IP address with a private NAT gateway. If the Elastic IP address is associated with another resource, you must first disassociate it.

availability_mode class-attribute instance-attribute
availability_mode: str | None = ...

Specifies whether to create a zonal (single-AZ) or regional (multi-AZ) NAT gateway. Defaults to zonal.

A zonal NAT gateway is a NAT Gateway that provides redundancy and scalability within a single availability zone. A regional NAT gateway is a single NAT Gateway that works across multiple availability zones (AZs) in your VPC, providing redundancy, scalability and availability across all the AZs in a Region.

For more information, see Regional NAT gateways for automatic multi-AZ expansion in the Amazon VPC User Guide.

availability_zone_addresses class-attribute instance-attribute
availability_zone_addresses: list[AvailabilityZoneAddress] | None = ...

For regional NAT gateways only: Specifies which Availability Zones you want the NAT gateway to support and the Elastic IP addresses (EIPs) to use in each AZ. The regional NAT gateway uses these EIPs to handle outbound NAT traffic from their respective AZs. If not specified, the NAT gateway will automatically expand to new AZs and associate EIPs upon detection of an elastic network interface. If you specify this parameter, auto-expansion is disabled and you must manually manage AZ coverage.

A regional NAT gateway is a single NAT Gateway that works across multiple availability zones (AZs) in your VPC, providing redundancy, scalability and availability across all the AZs in a Region.

For more information, see Regional NAT gateways for automatic multi-AZ expansion in the Amazon VPC User Guide.

client_token class-attribute instance-attribute
client_token: str | None = ...

Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. For more information, see Ensuring idempotency.

Constraint: Maximum 64 ASCII characters.

This field is autopopulated if not provided.

connectivity_type class-attribute instance-attribute
connectivity_type: str | None = ...

Indicates whether the NAT gateway supports public or private connectivity. The default is public connectivity.

dry_run class-attribute instance-attribute
dry_run: bool | None = ...

Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

private_ip_address class-attribute instance-attribute
private_ip_address: str | None = ...

The private IPv4 address to assign to the NAT gateway. If you don't provide an address, a private IPv4 address will be automatically assigned.

secondary_allocation_ids class-attribute instance-attribute
secondary_allocation_ids: list[str] | None = ...

Secondary EIP allocation IDs. For more information, see Create a NAT gateway in the Amazon VPC User Guide.

secondary_private_ip_address_count class-attribute instance-attribute
secondary_private_ip_address_count: int | None = ...

[Private NAT gateway only] The number of secondary private IPv4 addresses you want to assign to the NAT gateway. For more information about secondary addresses, see Create a NAT gateway in the Amazon VPC User Guide.

secondary_private_ip_addresses class-attribute instance-attribute
secondary_private_ip_addresses: list[str] | None = ...

Secondary private IPv4 addresses. For more information about secondary addresses, see Create a NAT gateway in the Amazon VPC User Guide.

subnet_id class-attribute instance-attribute
subnet_id: str | None = ...

The ID of the subnet in which to create the NAT gateway.

tag_specifications class-attribute instance-attribute
tag_specifications: list[TagSpecification] | None = ...

The tags to assign to the NAT gateway.

vpc_id class-attribute instance-attribute
vpc_id: str | None = ...

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

Output

CreateNatGatewayOutput dataclass

Bases: _SerdeShape

Dataclass for CreateNatGatewayOutput structure.

Attributes

client_token class-attribute instance-attribute
client_token: str | None = ...

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

nat_gateway class-attribute instance-attribute
nat_gateway: NatGateway | None = ...

Information about the NAT gateway.

response_metadata class-attribute instance-attribute
response_metadata: ResponseMetadata = ...

Metadata about the response that produced this output. Use this to recover the request identifiers a service's support team needs in order to investigate a call. Members of the metadata are individually optional.