# NatInstanceProvider

NAT provider which uses NAT Instances.

Extends: [NatProvider](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.NatProvider.html) › NatInstanceProvider
Implements: [IConnectable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IConnectable.html)
Obtainable from: [NatProvider.instance](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.NatProvider.html#instance)

- 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#L605)
- Type last changed: v2.132.0 · 9 Mar 2024

## Example

TypeScript:

```ts
const natInstanceProvider = ec2.NatProvider.instance({
  instanceType: ec2.InstanceType.of(ec2.InstanceClass.T4G, ec2.InstanceSize.LARGE),
  machineImage: new ec2.AmazonLinuxImage(),
  creditSpecification: ec2.CpuCredits.UNLIMITED,
});
new ec2.Vpc(this, 'VPC', {
  natGatewayProvider: natInstanceProvider,
});
```

Python:

```python
nat_instance_provider = ec2.NatProvider.instance(
    instance_type=ec2.InstanceType.of(ec2.InstanceClass.T4G, ec2.InstanceSize.LARGE),
    machine_image=ec2.AmazonLinuxImage(),
    credit_specification=ec2.CpuCredits.UNLIMITED
)
ec2.Vpc(self, "VPC",
    nat_gateway_provider=nat_instance_provider
)
```

Java:

```java
NatInstanceProvider natInstanceProvider = NatProvider.instance(NatInstanceProps.builder()
        .instanceType(InstanceType.of(InstanceClass.T4G, InstanceSize.LARGE))
        .machineImage(new AmazonLinuxImage())
        .creditSpecification(CpuCredits.UNLIMITED)
        .build());
Vpc.Builder.create(this, "VPC")
        .natGatewayProvider(natInstanceProvider)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var natInstanceProvider = NatProvider.Instance(new NatInstanceProps {
    InstanceType = InstanceType.Of(InstanceClass.T4G, InstanceSize.LARGE),
    MachineImage = new AmazonLinuxImage(),
    CreditSpecification = CpuCredits.UNLIMITED
});
new Vpc(this, "VPC", new VpcProps {
    NatGatewayProvider = natInstanceProvider
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
natInstanceProvider := ec2.NatProvider_Instance(&NatInstanceProps{
	InstanceType: ec2.InstanceType_Of(ec2.InstanceClass_T4G, ec2.InstanceSize_LARGE),
	MachineImage: ec2.NewAmazonLinuxImage(),
	CreditSpecification: ec2.CpuCredits_UNLIMITED,
})
ec2.NewVpc(this, jsii.String("VPC"), &VpcProps{
	NatGatewayProvider: natInstanceProvider,
})
```

## Initializer

TypeScript:

```ts
new NatInstanceProvider(props: NatInstanceProps)
```

Python:

```python
NatInstanceProvider(props: NatInstanceProps)
```

Java:

```java
new NatInstanceProvider(NatInstanceProps props)
```

C# / .NET:

```csharp
new NatInstanceProvider(NatInstanceProps props)
```

Golang:

```go
NewNatInstanceProvider(Props NatInstanceProps)
```

## 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.

- `connections`: [Connections](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Connections.html) — Manage the Security Groups associated with the NAT instances.

- `securityGroup`: [ISecurityGroup](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html) — The Security Group associated with the NAT instances.

## 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 // chainable` (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.
