class NatGateway (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.ec2.Alpha.NatGateway |
Go | github.com/aws/aws-cdk-go/awsec2alpha/v2#NatGateway |
Java | software.amazon.awscdk.services.ec2.alpha.NatGateway |
Python | aws_cdk.aws_ec2_alpha.NatGateway |
TypeScript (source) | @aws-cdk/aws-ec2-alpha ยป NatGateway |
Implements
IConstruct
, IDependable
, IResource
, IRoute
Creates a network address translation (NAT) gateway.
Example
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 },
});
Initializer
new NatGateway(scope: Construct, id: string, props: NatGatewayProps)
Parameters
- scope
Construct
- id
string
- props
Nat
Gateway Props
Construct Props
Name | Type | Description |
---|---|---|
subnet | ISubnet | The subnet in which the NAT gateway is located. |
allocation | string | AllocationID of Elastic IP address that's associated with the NAT gateway. |
connectivity | Nat | Indicates whether the NAT gateway supports public or private connectivity. |
max | Duration | The maximum amount of time to wait before forcibly releasing the IP addresses if connections are still in progress. |
nat | string | The resource name of the NAT gateway. |
private | string | The private IPv4 address to assign to the NAT gateway. |
secondary | string[] | Secondary EIP allocation IDs. |
secondary | number | The number of secondary private IPv4 addresses you want to assign to the NAT gateway. |
secondary | string[] | Secondary private IPv4 addresses. |
vpc? | IVpc | The ID of the VPC in which the NAT gateway is located. |
subnet
Type:
ISubnet
The subnet in which the NAT gateway is located.
allocationId?
Type:
string
(optional, default: attr.allocationID of a new Elastic IP created by default
//TODO: ADD L2 for elastic ip)
AllocationID of Elastic IP address that's associated with the NAT gateway.
This property is required for a public NAT gateway and cannot be specified with a private NAT gateway.
connectivityType?
Type:
Nat
(optional, default: NatConnectivityType.Public)
Indicates whether the NAT gateway supports public or private connectivity.
maxDrainDuration?
Type:
Duration
(optional, default: 350seconds)
The maximum amount of time to wait before forcibly releasing the IP addresses if connections are still in progress.
natGatewayName?
Type:
string
(optional, default: NATGW provisioned without any name)
The resource name of the NAT gateway.
privateIpAddress?
Type:
string
(optional, default: If you don't provide an address, a private IPv4 address will be automatically assigned.)
The private IPv4 address to assign to the NAT gateway.
secondaryAllocationIds?
Type:
string[]
(optional, default: no secondary allocation IDs attached to NATGW)
Secondary EIP allocation IDs.
See also: https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html#nat-gateway-creating
secondaryPrivateIpAddressCount?
Type:
number
(optional, default: no secondary allocation IDs associated with NATGW)
The number of secondary private IPv4 addresses you want to assign to the NAT gateway.
SecondaryPrivateIpAddressCount
and SecondaryPrivateIpAddresses
cannot be
set at the same time.
See also: https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html#nat-gateway-creating
secondaryPrivateIpAddresses?
Type:
string[]
(optional, default: no secondary private IpAddresses associated with NATGW)
Secondary private IPv4 addresses.
SecondaryPrivateIpAddressCount
and SecondaryPrivateIpAddresses
cannot be
set at the same time.
See also: https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html#nat-gateway-creating
vpc?
Type:
IVpc
(optional, default: no elastic ip associated, required in case of public connectivity if AllocationId
is not defined)
The ID of the VPC in which the NAT gateway is located.
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
node | Node | The tree node. |
resource | Cfn | The NAT gateway CFN resource. |
router | string | The ID of the route target. |
router | Router | The type of router used in the route. |
stack | Stack | The stack in which this resource is defined. |
connectivity | Nat | Indicates whether the NAT gateway supports public or private connectivity. |
max | Duration | The maximum amount of time to wait before forcibly releasing the IP addresses if connections are still in progress. |
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
node
Type:
Node
The tree node.
resource
Type:
Cfn
The NAT gateway CFN resource.
routerTargetId
Type:
string
The ID of the route target.
routerType
Type:
Router
The type of router used in the route.
stack
Type:
Stack
The stack in which this resource is defined.
connectivityType?
Type:
Nat
(optional, default: public)
Indicates whether the NAT gateway supports public or private connectivity.
maxDrainDuration?
Type:
Duration
(optional, default: '350 seconds')
The maximum amount of time to wait before forcibly releasing the IP addresses if connections are still in progress.
Methods
Name | Description |
---|---|
apply | Apply the given removal policy to this resource. |
to | Returns a string representation of this construct. |
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.