Skip to content
v2.277.0

Experimental

@aws-cdk/aws-ec2-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

NatGatewayProps Struct ​

Properties to define a NAT gateway.

Example ​

ts
const myVpc = new VpcV2(this, 'Vpc');
const routeTable = new RouteTable(this, 'RouteTable', {
  vpc: myVpc,
});
const subnet = new SubnetV2(this, 'Subnet', {
  vpc: myVpc,
  availabilityZone: 'eu-west-2a',
  ipv4CidrBlock: new IpCidr('10.0.0.0/24'),
  subnetType: SubnetType.PRIVATE_ISOLATED });

const natgw = new NatGateway(this, 'NatGW', {
  subnet: subnet,
  vpc: myVpc,
  connectivityType: NatConnectivityType.PRIVATE,
  privateIpAddress: '10.0.0.42',
});
new Route(this, 'NatGwRoute', {
  routeTable,
  destination: '0.0.0.0/0',
  target: { gateway: natgw },
});
python
my_vpc = VpcV2(self, "Vpc")
route_table = RouteTable(self, "RouteTable",
    vpc=my_vpc
)
subnet = SubnetV2(self, "Subnet",
    vpc=my_vpc,
    availability_zone="eu-west-2a",
    ipv4_cidr_block=IpCidr("10.0.0.0/24"),
    subnet_type=SubnetType.PRIVATE_ISOLATED
)

natgw = NatGateway(self, "NatGW",
    subnet=subnet,
    vpc=my_vpc,
    connectivity_type=NatConnectivityType.PRIVATE,
    private_ip_address="10.0.0.42"
)
Route(self, "NatGwRoute",
    route_table=route_table,
    destination="0.0.0.0/0",
    target={"gateway": natgw}
)
java
VpcV2 myVpc = new VpcV2(this, "Vpc");
RouteTable routeTable = RouteTable.Builder.create(this, "RouteTable")
        .vpc(myVpc)
        .build();
SubnetV2 subnet = SubnetV2.Builder.create(this, "Subnet")
        .vpc(myVpc)
        .availabilityZone("eu-west-2a")
        .ipv4CidrBlock(new IpCidr("10.0.0.0/24"))
        .subnetType(SubnetType.PRIVATE_ISOLATED)
        .build();

NatGateway natgw = NatGateway.Builder.create(this, "NatGW")
        .subnet(subnet)
        .vpc(myVpc)
        .connectivityType(NatConnectivityType.PRIVATE)
        .privateIpAddress("10.0.0.42")
        .build();
Route.Builder.create(this, "NatGwRoute")
        .routeTable(routeTable)
        .destination("0.0.0.0/0")
        .target(Map.of("gateway", natgw))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.AWS.ec2.Alpha
var myVpc = new VpcV2(this, "Vpc");
var routeTable = new RouteTable(this, "RouteTable", new RouteTableProps {
    Vpc = myVpc
});
var subnet = new SubnetV2(this, "Subnet", new SubnetV2Props {
    Vpc = myVpc,
    AvailabilityZone = "eu-west-2a",
    Ipv4CidrBlock = new IpCidr("10.0.0.0/24"),
    SubnetType = SubnetType.PRIVATE_ISOLATED
});

var natgw = new NatGateway(this, "NatGW", new NatGatewayProps {
    Subnet = subnet,
    Vpc = myVpc,
    ConnectivityType = NatConnectivityType.PRIVATE,
    PrivateIpAddress = "10.0.0.42"
});
new Route(this, "NatGwRoute", new RouteProps {
    RouteTable = routeTable,
    Destination = "0.0.0.0/0",
    Target = new Dictionary<string, IRouteTarget?> { { "gateway", natgw } }
});
go
// Install: go get github.com/aws/aws-cdk-go/awsec2alpha/v2
myVpc := awsec2alpha.NewVpcV2(this, jsii.String("Vpc"))
routeTable := awsec2alpha.NewRouteTable(this, jsii.String("RouteTable"), &RouteTableProps{
	Vpc: myVpc,
})
subnet := awsec2alpha.NewSubnetV2(this, jsii.String("Subnet"), &SubnetV2Props{
	Vpc: myVpc,
	AvailabilityZone: jsii.String("eu-west-2a"),
	Ipv4CidrBlock: awsec2alpha.NewIpCidr(jsii.String("10.0.0.0/24")),
	SubnetType: awscdk.SubnetType_PRIVATE_ISOLATED,
})

natgw := awsec2alpha.NewNatGateway(this, jsii.String("NatGW"), &NatGatewayProps{
	Subnet: subnet,
	Vpc: myVpc,
	ConnectivityType: awsec2alpha.NatConnectivityType_PRIVATE,
	PrivateIpAddress: jsii.String("10.0.0.42"),
})
awsec2alpha.NewRoute(this, jsii.String("NatGwRoute"), &RouteProps{
	RouteTable: RouteTable,
	Destination: jsii.String("0.0.0.0/0"),
	Target: map[string]iRouteTarget{
		"gateway": natgw,
	},
})

Properties ​

allocationIdoptionalstringallocation_idoptionalstrallocationIdoptionalStringAllocationIdoptionalstringAllocationIdoptional*string #
AllocationID of Elastic IP address that's associated with the NAT gateway.

Default: attr.allocationID of a new Elastic IP created by default //TODO: ADD L2 for elastic ip

This property is required for a public NAT gateway and cannot be specified with a private NAT gateway.

connectivityTypeoptionalNatConnectivityTypeconnectivity_typeoptionalNatConnectivityTypeconnectivityTypeoptionalNatConnectivityTypeConnectivityTypeoptionalNatConnectivityTypeConnectivityTypeoptionalNatConnectivityType = NatConnectivityType.Public #
Indicates whether the NAT gateway supports public or private connectivity.
maxDrainDurationoptionalDurationmax_drain_durationoptionalDurationmaxDrainDurationoptionalDurationMaxDrainDurationoptionalDurationMaxDrainDurationoptionalDuration = Duration.seconds(350) #
The maximum amount of time to wait before forcibly releasing the IP addresses if connections are still in progress.
natGatewayNameoptionalstringnat_gateway_nameoptionalstrnatGatewayNameoptionalStringNatGatewayNameoptionalstringNatGatewayNameoptional*string #
The resource name of the NAT gateway.

Default: NATGW provisioned without any name

privateIpAddressoptionalstringprivate_ip_addressoptionalstrprivateIpAddressoptionalStringPrivateIpAddressoptionalstringPrivateIpAddressoptional*string #
The private IPv4 address to assign to the NAT gateway.

Default: If you don't provide an address, a private IPv4 address will be automatically assigned.

secondaryAllocationIdsoptionalstring[]secondary_allocation_idsoptionaltyping.List[str]secondaryAllocationIdsoptionalList<String>SecondaryAllocationIdsoptionalstring[]SecondaryAllocationIdsoptional*[]*string #
Secondary EIP allocation IDs.

Default: no secondary allocation IDs attached to NATGW

secondaryPrivateIpAddressCountoptionalnumbersecondary_private_ip_address_countoptionalint | floatsecondaryPrivateIpAddressCountoptionalNumberSecondaryPrivateIpAddressCountoptionaldoubleSecondaryPrivateIpAddressCountoptional*float64 #
The number of secondary private IPv4 addresses you want to assign to the NAT gateway.

Default: no secondary allocation IDs associated with NATGW

SecondaryPrivateIpAddressCount and SecondaryPrivateIpAddresses cannot be set at the same time.

secondaryPrivateIpAddressesoptionalstring[]secondary_private_ip_addressesoptionaltyping.List[str]secondaryPrivateIpAddressesoptionalList<String>SecondaryPrivateIpAddressesoptionalstring[]SecondaryPrivateIpAddressesoptional*[]*string #
Secondary private IPv4 addresses.

Default: no secondary private IpAddresses associated with NATGW

SecondaryPrivateIpAddressCount and SecondaryPrivateIpAddresses cannot be set at the same time.

subnetISubnetV2subnetISubnetV2subnetISubnetV2SubnetISubnetV2SubnetISubnetV2 required #
The subnet in which the NAT gateway is located.
vpcoptionalIVpcV2vpcoptionalIVpcV2vpcoptionalIVpcV2VpcoptionalIVpcV2VpcoptionalIVpcV2 #
The ID of the VPC in which the NAT gateway is located.

Default: no elastic ip associated, required in case of public connectivity if AllocationId is not defined