class VpcV2 (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.ec2.Alpha.VpcV2 |
![]() | github.com/aws/aws-cdk-go/awsec2alpha/v2#VpcV2 |
![]() | software.amazon.awscdk.services.ec2.alpha.VpcV2 |
![]() | aws_cdk.aws_ec2_alpha.VpcV2 |
![]() | @aws-cdk/aws-ec2-alpha ยป VpcV2 |
Implements
IConstruct
, IDependable
, IResource
, IVpc
, IVpc
This class provides a foundation for creating and configuring a VPC with advanced features such as IPAM (IP Address Management) and IPv6 support.
For more information, see the {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Vpc.html AWS CDK Documentation on VPCs}.
Example
const stack = new Stack();
const myVpc = new VpcV2(this, 'Vpc',{
primaryAddressBlock: IpAddresses.ipv4('10.1.0.0/16'),
secondaryAddressBlocks: [IpAddresses.amazonProvidedIpv6({
cidrBlockName: 'AmazonProvided',
})]
});
const eigw = new EgressOnlyInternetGateway(this, 'EIGW', {
vpc: myVpc,
});
const routeTable = new RouteTable(this, 'RouteTable', {
vpc: myVpc,
});
routeTable.addRoute('EIGW', '::/0', { gateway: eigw });
Initializer
new VpcV2(scope: Construct, id: string, props?: VpcV2Props)
Parameters
- scope
Construct
- id
string
- props
Vpc
V2 Props
Construct Props
Name | Type | Description |
---|---|---|
default | Default | The default tenancy of instances launched into the VPC. |
enable | boolean | Indicates whether the instances launched in the VPC get DNS hostnames. |
enable | boolean | Indicates whether the DNS resolution is supported for the VPC. |
primary | IIp | A must IPv4 CIDR block for the VPC. |
secondary | IIp [] | The secondary CIDR blocks associated with the VPC. |
vpc | string | Physical name for the VPC. |
defaultInstanceTenancy?
Type:
Default
(optional, default: DefaultInstanceTenancy.Default (shared) tenancy)
The default tenancy of instances launched into the VPC.
By setting this to dedicated tenancy, instances will be launched on hardware dedicated to a single AWS customer, unless specifically specified at instance launch time. Please note, not all instance types are usable with Dedicated tenancy.
enableDnsHostnames?
Type:
boolean
(optional, default: true)
Indicates whether the instances launched in the VPC get DNS hostnames.
enableDnsSupport?
Type:
boolean
(optional, default: true)
Indicates whether the DNS resolution is supported for the VPC.
primaryAddressBlock?
Type:
IIp
(optional, default: Ipv4 CIDR Block ('10.0.0.0/16'))
A must IPv4 CIDR block for the VPC.
See also: https://docs.aws.amazon.com/vpc/latest/userguide/vpc-cidr-blocks.html
secondaryAddressBlocks?
Type:
IIp
[]
(optional, default: No secondary IP address)
The secondary CIDR blocks associated with the VPC.
Can be IPv4 or IPv6, two IPv4 ranges must follow RFC#1918 convention For more information,
vpcName?
Type:
string
(optional, default: autogenerated by CDK)
Physical name for the VPC.
Properties
Name | Type | Description |
---|---|---|
availability | string[] | AZs for this VPC. |
dns | boolean | Indicates if instances launched in this VPC will have public DNS hostnames. |
dns | boolean | Indicates if DNS support is enabled for this VPC. |
env | Resource | The environment this resource belongs to. |
internet | IDependable | To define dependency on internet connectivity. |
ip | IIp | The provider of ipv4 addresses. |
ipv4 | string | The primary IPv4 CIDR block associated with the VPC. |
ipv6 | string[] | The IPv6 CIDR blocks for the VPC. |
isolated | ISubnet [] | Isolated Subnets that are part of this VPC. |
node | Node | The tree node. |
owner | string | Identifier of the owner for this VPC. |
private | ISubnet [] | Public Subnets that are part of this VPC. |
public | ISubnet [] | Public Subnets that are part of this VPC. |
region | string | Region for this VPC. |
resource | Cfn | The AWS CloudFormation resource representing the VPC. |
stack | Stack | The stack in which this resource is defined. |
use | boolean | For validation to define IPv6 subnets, set to true in case of Amazon Provided IPv6 cidr range if true, IPv6 addresses can be attached to the subnets. |
vpc | string | Arn of this VPC. |
vpc | string | CIDR range for this VPC. |
vpc | string | Identifier for this VPC. |
egress | string | Returns the id of the Egress Only Internet Gateway (if enabled). |
internet | string | Returns the id of the Internet Gateway (if enabled). |
ipv4 | string[] | IPv4 CIDR provisioned using IPAM pool Required to check for overlapping CIDRs after provisioning is complete under IPAM. |
secondary | IVPCCidr [] | reference to all secondary blocks attached. |
vpc | string | VpcName to be used for tagging its components. |
vpn | string | Returns the id of the VPN Gateway (if enabled). |
availabilityZones
Type:
string[]
AZs for this VPC.
dnsHostnamesEnabled
Type:
boolean
Indicates if instances launched in this VPC will have public DNS hostnames.
dnsSupportEnabled
Type:
boolean
Indicates if DNS support is enabled for this VPC.
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.
internetConnectivityEstablished
Type:
IDependable
To define dependency on internet connectivity.
ipAddresses
Type:
IIp
The provider of ipv4 addresses.
ipv4CidrBlock
Type:
string
The primary IPv4 CIDR block associated with the VPC.
Needed in order to validate the vpc range of subnet current prop vpcCidrBlock refers to the token value For more information, see the {@link https://docs.aws.amazon.com/vpc/latest/userguide/vpc-cidr-blocks.html#vpc-sizing-ipv4}.
ipv6CidrBlocks
Type:
string[]
The IPv6 CIDR blocks for the VPC.
isolatedSubnets
Type:
ISubnet
[]
Isolated Subnets that are part of this VPC.
node
Type:
Node
The tree node.
ownerAccountId
Type:
string
Identifier of the owner for this VPC.
privateSubnets
Type:
ISubnet
[]
Public Subnets that are part of this VPC.
publicSubnets
Type:
ISubnet
[]
Public Subnets that are part of this VPC.
region
Type:
string
Region for this VPC.
resource
Type:
Cfn
The AWS CloudFormation resource representing the VPC.
stack
Type:
Stack
The stack in which this resource is defined.
useIpv6
Type:
boolean
For validation to define IPv6 subnets, set to true in case of Amazon Provided IPv6 cidr range if true, IPv6 addresses can be attached to the subnets.
vpcArn
Type:
string
Arn of this VPC.
vpcCidrBlock
Type:
string
CIDR range for this VPC.
vpcId
Type:
string
Identifier for this VPC.
egressOnlyInternetGatewayId?
Type:
string
(optional)
Returns the id of the Egress Only Internet Gateway (if enabled).
internetGatewayId?
Type:
string
(optional)
Returns the id of the Internet Gateway (if enabled).
ipv4IpamProvisionedCidrs?
Type:
string[]
(optional)
IPv4 CIDR provisioned using IPAM pool Required to check for overlapping CIDRs after provisioning is complete under IPAM.
secondaryCidrBlock?
Type:
IVPCCidr
[]
(optional)
reference to all secondary blocks attached.
vpcName?
Type:
string
(optional)
VpcName to be used for tagging its components.
vpnGatewayId?
Type:
string
(optional)
Returns the id of the VPN Gateway (if enabled).
Methods
Name | Description |
---|---|
add | Adds a new client VPN endpoint to this VPC. |
add | Adds a new Egress Only Internet Gateway to this VPC and defines a new route to the route table of given subnets. |
add | Adds a new flow log to this VPC. |
add | Adds a new gateway endpoint to this VPC. |
add | Adds a new interface endpoint to this VPC. |
add | Adds a new Internet Gateway to this VPC. |
add | Adds a new NAT Gateway to the given subnet of this VPC of given subnets. |
add | Adds a new VPN connection to this VPC. |
apply | Apply the given removal policy to this resource. |
create | Creates peering connection role for acceptor VPC. |
create | Creates a peering connection. |
enable | Adds a VPN Gateway to this VPC. |
enable | Adds VPNGAtewayV2 to this VPC. |
select | Return information on the subnets appropriate for the given selection strategy. |
to | Returns a string representation of this construct. |
static from | Create a VPC from existing attributes. |
addClientVpnEndpoint(id, options)
public addClientVpnEndpoint(id: string, options: ClientVpnEndpointOptions): ClientVpnEndpoint
Parameters
- id
string
- options
Client
Vpn Endpoint Options
Returns
Adds a new client VPN endpoint to this VPC.
addEgressOnlyInternetGateway(options?)
public addEgressOnlyInternetGateway(options?: EgressOnlyInternetGatewayOptions): void
Parameters
- options
Egress
Only Internet Gateway Options
Adds a new Egress Only Internet Gateway to this VPC and defines a new route to the route table of given subnets.
addFlowLog(id, options?)
public addFlowLog(id: string, options?: FlowLogOptions): FlowLog
Parameters
- id
string
- options
Flow
Log Options
Returns
Adds a new flow log to this VPC.
addGatewayEndpoint(id, options)
public addGatewayEndpoint(id: string, options: GatewayVpcEndpointOptions): GatewayVpcEndpoint
Parameters
- id
string
- options
Gateway
Vpc Endpoint Options
Returns
Adds a new gateway endpoint to this VPC.
addInterfaceEndpoint(id, options)
public addInterfaceEndpoint(id: string, options: InterfaceVpcEndpointOptions): InterfaceVpcEndpoint
Parameters
- id
string
- options
Interface
Vpc Endpoint Options
Returns
Adds a new interface endpoint to this VPC.
addInternetGateway(options?)
public addInternetGateway(options?: InternetGatewayOptions): void
Parameters
- options
Internet
Gateway Options
Adds a new Internet Gateway to this VPC.
addNatGateway(options)
public addNatGateway(options: NatGatewayOptions): NatGateway
Parameters
- options
Nat
Gateway Options
Returns
Adds a new NAT Gateway to the given subnet of this VPC of given subnets.
addVpnConnection(id, options)
public addVpnConnection(id: string, options: VpnConnectionOptions): VpnConnection
Parameters
- id
string
- options
Vpn
Connection Options
Returns
Adds a new VPN connection to this VPC.
applyRemovalPolicy(policy)
public 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
).
createAcceptorVpcRole(requestorAccountId)
public createAcceptorVpcRole(requestorAccountId: string): Role
Parameters
- requestorAccountId
string
Returns
Creates peering connection role for acceptor VPC.
createPeeringConnection(id, options)
public createPeeringConnection(id: string, options: VPCPeeringConnectionOptions): VPCPeeringConnection
Parameters
- id
string
- options
VPCPeering
Connection Options
Returns
Creates a peering connection.
enableVpnGateway(options)
public enableVpnGateway(options: EnableVpnGatewayOptions): void
โ ๏ธ Deprecated: use enableVpnGatewayV2 for compatibility with VPCV2.Route
Parameters
- options
Enable
Vpn Gateway Options
Adds a VPN Gateway to this VPC.
enableVpnGatewayV2(options)
public enableVpnGatewayV2(options: VPNGatewayV2Options): VPNGatewayV2
Parameters
- options
VPNGateway
V2 Options
Returns
Adds VPNGAtewayV2 to this VPC.
selectSubnets(selection?)
public selectSubnets(selection?: SubnetSelection): SelectedSubnets
Parameters
- selection
Subnet
Selection
Returns
Return information on the subnets appropriate for the given selection strategy.
Requires that at least one subnet is matched, throws a descriptive error message otherwise.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
static fromVpcV2Attributes(scope, id, attrs)
public static fromVpcV2Attributes(scope: Construct, id: string, attrs: VpcV2Attributes): IVpcV2
Parameters
- scope
Construct
- id
string
- attrs
Vpc
V2 Attributes
Returns
Create a VPC from existing attributes.