# NatGatewayProvider

Provider for NAT Gateways.

Extends: [NatProvider](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.NatProvider.html) › NatGatewayProvider

- Source: [`aws-ec2/lib/nat.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-ec2/lib/nat.ts#L404)
- Type last changed: v2.151.0 · 2 Aug 2024

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_ec2 as ec2 } from 'aws-cdk-lib';
const natGatewayProvider = new ec2.NatGatewayProvider(/* all optional props */ {
  eipAllocationIds: ['eipAllocationIds'],
  maxDrainDuration: cdk.Duration.minutes(30),
});
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk
from aws_cdk import aws_ec2 as ec2

nat_gateway_provider = ec2.NatGatewayProvider(
    eip_allocation_ids=["eipAllocationIds"],
    max_drain_duration=cdk.Duration.minutes(30)
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.ec2.*;

NatGatewayProvider natGatewayProvider = NatGatewayProvider.Builder.create()
        .eipAllocationIds(List.of("eipAllocationIds"))
        .maxDrainDuration(Duration.minutes(30))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK;
using Amazon.CDK.AWS.EC2;

var natGatewayProvider = new NatGatewayProvider(new NatGatewayProps {
    EipAllocationIds = new [] { "eipAllocationIds" },
    MaxDrainDuration = Duration.Minutes(30)
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import cdk "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

natGatewayProvider := awscdk.Aws_ec2.NewNatGatewayProvider(&NatGatewayProps{
	EipAllocationIds: []*string{
		jsii.String("eipAllocationIds"),
	},
	MaxDrainDuration: cdk.Duration_Minutes(jsii.Number(30)),
})
```

## Initializer

TypeScript:

```ts
new NatGatewayProvider(props?: NatGatewayProps)
```

Python:

```python
NatGatewayProvider(props: typing.Optional[NatGatewayProps] = None)
```

Java:

```java
new NatGatewayProvider(NatGatewayProps props)
```

C# / .NET:

```csharp
new NatGatewayProvider(NatGatewayProps? props = null)
```

Golang:

```go
NewNatGatewayProvider(Props NatGatewayProps)
```

## Properties

- `configuredGateways`: [GatewayConfig](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.GatewayConfig.html)[] — Return list of gateways spawned by the provider.

## Methods

- `configureNat(options: ConfigureNatOptions): void` — Called by the VPC to configure NAT.

  Don't call this directly, the VPC will call it automatically.

- `configureSubnet(subnet: PrivateSubnet): void` — Configures subnet with the gateway.

  Don't call this directly, the VPC will call it automatically.

- `gateway(props?: NatGatewayProps): NatProvider` (static) — Use NAT Gateways to provide NAT services for your VPC.

  NAT gateways are managed by AWS.

- `instance(props: NatInstanceProps): NatInstanceProvider` (static) — use instanceV2. 'instance' is deprecated since NatInstanceProvider uses a instance image that has reached EOL on Dec 31 2023

  NAT instances are managed by you, but in return allow more configuration.

  Be aware that instances created using this provider will not be
  automatically replaced if they are stopped for any reason. You should implement
  your own NatProvider based on AutoScaling groups if you need that.

- `instanceV2(props: NatInstanceProps): NatInstanceProviderV2` (static) — Use NAT instances to provide NAT services for your VPC.

  NAT instances are managed by you, but in return allow more configuration.

  Be aware that instances created using this provider will not be
  automatically replaced if they are stopped for any reason. You should implement
  your own NatProvider based on AutoScaling groups if you need that.

- `regionalGateway(props?: RegionalNatGatewayProviderProps): RegionalNatGatewayProvider` (static) — Use a Regional NAT Gateway to provide NAT services for your VPC.

  Regional NAT Gateways provide automatic multi-AZ redundancy with a single
  gateway that scales across availability zones. AWS automatically manages
  AZ coverage and EIP allocation.
