Skip to content
v2.274.0

NatInstanceProvider Class ​

NAT provider which uses NAT Instances.

Example ​

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
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
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();
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
});
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 ​

ts
new NatInstanceProvider(props: NatInstanceProps)
python
NatInstanceProvider(props: NatInstanceProps)
java
new NatInstanceProvider(NatInstanceProps props)
csharp
new NatInstanceProvider(NatInstanceProps props)
go
NewNatInstanceProvider(Props NatInstanceProps)

Properties ​

configuredGatewaysGatewayConfig[]configured_gatewaystyping.List[GatewayConfig]configuredGatewaysList<GatewayConfig>ConfiguredGatewaysGatewayConfig[]ConfiguredGateways*[]GatewayConfigrequired#
Return list of gateways spawned by the provider.
connectionsConnectionsconnectionsConnectionsconnectionsConnectionsConnectionsConnectionsConnectionsConnectionsrequired#
Manage the Security Groups associated with the NAT instances.
securityGroupISecurityGroupsecurity_groupISecurityGroupsecurityGroupISecurityGroupSecurityGroupISecurityGroupSecurityGroupISecurityGrouprequired#
The Security Group associated with the NAT instances.

Methods ​

configureNat(options: ConfigureNatOptions): voiddef configure_nat(self, options: ConfigureNatOptions) -> Nonepublic void configureNat(ConfigureNatOptions options)public void ConfigureNat(ConfigureNatOptions options)func ConfigureNat(Options ConfigureNatOptions)#
Called by the VPC to configure NAT.

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

configureSubnet(subnet: PrivateSubnet): voiddef configure_subnet(self, subnet: PrivateSubnet) -> Nonepublic void configureSubnet(PrivateSubnet subnet)public void ConfigureSubnet(PrivateSubnet subnet)func ConfigureSubnet(Subnet PrivateSubnet)#
Configures subnet with the gateway.

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

gateway(props?: NatGatewayProps): NatProvider@staticmethod def gateway(props: typing.Optional[NatGatewayProps] = None) -> NatProviderpublic static NatProvider gateway(NatGatewayProps props)public static NatProvider Gateway(NatGatewayProps? props = null)func Gateway(Props NatGatewayProps) NatProviderstatic#
Use NAT Gateways to provide NAT services for your VPC.

NAT gateways are managed by AWS.

instance(props: NatInstanceProps): NatInstanceProvider // chainable@staticmethod def instance(props: NatInstanceProps) -> NatInstanceProviderpublic static NatInstanceProvider instance(NatInstanceProps props)public static NatInstanceProvider Instance(NatInstanceProps props)func Instance(Props NatInstanceProps) NatInstanceProviderstaticdeprecated#
use instanceV2. 'instance' is deprecated since NatInstanceProvider uses a instance image that has reached EOL on Dec 31 2023
notes

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@staticmethod def instance_v2(props: NatInstanceProps) -> NatInstanceProviderV2public static NatInstanceProviderV2 instanceV2(NatInstanceProps props)public static NatInstanceProviderV2 InstanceV2(NatInstanceProps props)func InstanceV2(Props NatInstanceProps) NatInstanceProviderV2static#
Use NAT instances to provide NAT services for your VPC.
notes

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@staticmethod def regional_gateway(props: typing.Optional[RegionalNatGatewayProviderProps] = None) -> RegionalNatGatewayProviderpublic static RegionalNatGatewayProvider regionalGateway(RegionalNatGatewayProviderProps props)public static RegionalNatGatewayProvider RegionalGateway(RegionalNatGatewayProviderProps? props = null)func RegionalGateway(Props RegionalNatGatewayProviderProps) RegionalNatGatewayProviderstatic#
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.