@Generated(value="jsii-pacmak/1.74.0 (build 6d08790)", date="2023-03-28T21:34:22.366Z") public class Vpc extends Resource implements IVpc
See the package-level documentation of this package for an overview of the various dimensions in which you can configure your VPC.
For example:
Vpc vpc = Vpc.Builder.create(this, "TheVPC") .cidr("10.0.0.0/16") .build(); // Iterate the private subnets SelectedSubnets selection = vpc.selectSubnets(SubnetSelection.builder() .subnetType(SubnetType.PRIVATE_WITH_NAT) .build()); for (Object subnet : selection.getSubnets()) { }
Example:
import software.amazon.awscdk.services.ec2.*; Vpc vpc = Vpc.Builder.create(this, "Vpc") .cidr("10.0.0.0/16") .build(); VpcConnector vpcConnector = VpcConnector.Builder.create(this, "VpcConnector") .vpc(vpc) .vpcSubnets(vpc.selectSubnets(SubnetSelection.builder().subnetType(SubnetType.PUBLIC).build())) .vpcConnectorName("MyVpcConnector") .build(); Service.Builder.create(this, "Service") .source(Source.fromEcrPublic(EcrPublicProps.builder() .imageConfiguration(ImageConfiguration.builder().port(8000).build()) .imageIdentifier("public.ecr.aws/aws-containers/hello-app-runner:latest") .build())) .vpcConnector(vpcConnector) .build();
Modifier and Type | Class and Description |
---|---|
static class |
Vpc.Builder
A fluent builder for
Vpc . |
IVpc.Jsii$Default, IVpc.Jsii$Proxy
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_CIDR_RANGE
The default CIDR range used when creating VPCs.
|
static java.util.List<SubnetConfiguration> |
DEFAULT_SUBNETS
The default subnet configuration.
|
static java.util.List<SubnetConfiguration> |
DEFAULT_SUBNETS_NO_NAT
The default subnet configuration if natGateways specified to be 0.
|
Modifier | Constructor and Description |
---|---|
protected |
Vpc(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) |
protected |
Vpc(software.amazon.jsii.JsiiObjectRef objRef) |
|
Vpc(software.constructs.Construct scope,
java.lang.String id)
Vpc creates a VPC that spans a whole region.
|
|
Vpc(software.constructs.Construct scope,
java.lang.String id,
VpcProps props)
Vpc creates a VPC that spans a whole region.
|
Modifier and Type | Method and Description |
---|---|
ClientVpnEndpoint |
addClientVpnEndpoint(java.lang.String id,
ClientVpnEndpointOptions options)
Adds a new client VPN endpoint to this VPC.
|
GatewayVpcEndpoint |
addDynamoDbEndpoint(java.lang.String id)
Deprecated.
use `addGatewayEndpoint()` instead
|
GatewayVpcEndpoint |
addDynamoDbEndpoint(java.lang.String id,
java.util.List<SubnetSelection> subnets)
Deprecated.
use `addGatewayEndpoint()` instead
|
FlowLog |
addFlowLog(java.lang.String id)
Adds a new flow log to this VPC.
|
FlowLog |
addFlowLog(java.lang.String id,
FlowLogOptions options)
Adds a new flow log to this VPC.
|
GatewayVpcEndpoint |
addGatewayEndpoint(java.lang.String id,
GatewayVpcEndpointOptions options)
Adds a new gateway endpoint to this VPC.
|
InterfaceVpcEndpoint |
addInterfaceEndpoint(java.lang.String id,
InterfaceVpcEndpointOptions options)
Adds a new interface endpoint to this VPC.
|
GatewayVpcEndpoint |
addS3Endpoint(java.lang.String id)
Deprecated.
use `addGatewayEndpoint()` instead
|
GatewayVpcEndpoint |
addS3Endpoint(java.lang.String id,
java.util.List<SubnetSelection> subnets)
Deprecated.
use `addGatewayEndpoint()` instead
|
VpnConnection |
addVpnConnection(java.lang.String id,
VpnConnectionOptions options)
Adds a new VPN connection to this VPC.
|
void |
enableVpnGateway(EnableVpnGatewayOptions options)
Adds a VPN Gateway to this VPC.
|
static IVpc |
fromLookup(software.constructs.Construct scope,
java.lang.String id,
VpcLookupOptions options)
Import an existing VPC from by querying the AWS environment this stack is deployed to.
|
static IVpc |
fromVpcAttributes(software.constructs.Construct scope,
java.lang.String id,
VpcAttributes attrs)
Import a VPC by supplying all attributes directly.
|
java.util.List<java.lang.String> |
getAvailabilityZones()
AZs for this VPC.
|
java.lang.Boolean |
getDnsHostnamesEnabled()
Indicates if instances launched in this VPC will have public DNS hostnames.
|
java.lang.Boolean |
getDnsSupportEnabled()
Indicates if DNS support is enabled for this VPC.
|
protected java.lang.Boolean |
getIncompleteSubnetDefinition()
If this is set to true, don't error out on trying to select subnets.
|
IDependable |
getInternetConnectivityEstablished()
Dependencies for internet connectivity.
|
java.lang.String |
getInternetGatewayId()
Internet Gateway for the VPC.
|
java.util.List<ISubnet> |
getIsolatedSubnets()
List of isolated subnets in this VPC.
|
protected java.util.List<IConstruct> |
getNatDependencies()
Deprecated.
- This value is no longer used.
|
java.util.List<ISubnet> |
getPrivateSubnets()
List of private subnets in this VPC.
|
java.util.List<ISubnet> |
getPublicSubnets()
List of public subnets in this VPC.
|
java.lang.String |
getVpcArn()
Arn of this VPC.
|
java.lang.String |
getVpcCidrBlock()
CIDR range for this VPC.
|
java.util.List<java.lang.String> |
getVpcCidrBlockAssociations() |
java.lang.String |
getVpcDefaultNetworkAcl() |
java.lang.String |
getVpcDefaultSecurityGroup() |
java.lang.String |
getVpcId()
Identifier for this VPC.
|
java.util.List<java.lang.String> |
getVpcIpv6CidrBlocks() |
java.lang.String |
getVpnGatewayId()
Returns the id of the VPN Gateway (if enabled).
|
protected java.util.List<ISubnet> |
selectSubnetObjects()
Return the subnets appropriate for the placement strategy.
|
protected java.util.List<ISubnet> |
selectSubnetObjects(SubnetSelection selection)
Return the subnets appropriate for the placement strategy.
|
SelectedSubnets |
selectSubnets()
Returns IDs of selected subnets.
|
SelectedSubnets |
selectSubnets(SubnetSelection selection)
Returns IDs of selected subnets.
|
protected void |
setIncompleteSubnetDefinition(java.lang.Boolean value)
If this is set to true, don't error out on trying to select subnets.
|
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isResource
getNode, isConstruct, onPrepare, onSynthesize, onValidate, prepare, synthesize, validate
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
applyRemovalPolicy, getEnv, getStack
getNode
public static final java.lang.String DEFAULT_CIDR_RANGE
This can be overridden using VpcProps when creating a VPCNetwork resource. e.g. new VpcResource(this, { cidr: '192.168.0.0./16' })
public static final java.util.List<SubnetConfiguration> DEFAULT_SUBNETS
1 Public and 1 Private subnet per AZ evenly split
public static final java.util.List<SubnetConfiguration> DEFAULT_SUBNETS_NO_NAT
1 Public and 1 Isolated Subnet per AZ evenly split
protected Vpc(software.amazon.jsii.JsiiObjectRef objRef)
protected Vpc(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
public Vpc(software.constructs.Construct scope, java.lang.String id, VpcProps props)
It will automatically divide the provided VPC CIDR range, and create public and private subnets per Availability Zone. Network routing for the public subnets will be configured to allow outbound access directly via an Internet Gateway. Network routing for the private subnets will be configured to allow outbound access via a set of resilient NAT Gateways (one per AZ).
scope
- This parameter is required.id
- This parameter is required.props
- public Vpc(software.constructs.Construct scope, java.lang.String id)
It will automatically divide the provided VPC CIDR range, and create public and private subnets per Availability Zone. Network routing for the public subnets will be configured to allow outbound access directly via an Internet Gateway. Network routing for the private subnets will be configured to allow outbound access via a set of resilient NAT Gateways (one per AZ).
scope
- This parameter is required.id
- This parameter is required.public static IVpc fromLookup(software.constructs.Construct scope, java.lang.String id, VpcLookupOptions options)
This function only needs to be used to use VPCs not defined in your CDK
application. If you are looking to share a VPC between stacks, you can
pass the Vpc
object between stacks and use it as normal.
Calling this method will lead to a lookup when the CDK CLI is executed. You can therefore not use any values that will only be available at CloudFormation execution time (i.e., Tokens).
The VPC information will be cached in cdk.context.json
and the same VPC
will be used on future runs. To refresh the lookup, you will have to
evict the value from the cache using the cdk context
command. See
https://docs.aws.amazon.com/cdk/latest/guide/context.html for more information.
scope
- This parameter is required.id
- This parameter is required.options
- This parameter is required.public static IVpc fromVpcAttributes(software.constructs.Construct scope, java.lang.String id, VpcAttributes attrs)
NOTE: using fromVpcAttributes()
with deploy-time parameters (like a Fn.importValue()
or
CfnParameter
to represent a list of subnet IDs) sometimes accidentally works. It happens
to work for constructs that need a list of subnets (like AutoScalingGroup
and eks.Cluster
)
but it does not work for constructs that need individual subnets (like
Instance
). See https://github.com/aws/aws-cdk/issues/4118 for more
information.
Prefer to use Vpc.fromLookup()
instead.
scope
- This parameter is required.id
- This parameter is required.attrs
- This parameter is required.public ClientVpnEndpoint addClientVpnEndpoint(java.lang.String id, ClientVpnEndpointOptions options)
addClientVpnEndpoint
in interface IVpc
id
- This parameter is required.options
- This parameter is required.@Deprecated public GatewayVpcEndpoint addDynamoDbEndpoint(java.lang.String id, java.util.List<SubnetSelection> subnets)
id
- This parameter is required.subnets
- @Deprecated public GatewayVpcEndpoint addDynamoDbEndpoint(java.lang.String id)
id
- This parameter is required.public FlowLog addFlowLog(java.lang.String id, FlowLogOptions options)
addFlowLog
in interface IVpc
id
- This parameter is required.options
- public FlowLog addFlowLog(java.lang.String id)
addFlowLog
in interface IVpc
id
- This parameter is required.public GatewayVpcEndpoint addGatewayEndpoint(java.lang.String id, GatewayVpcEndpointOptions options)
addGatewayEndpoint
in interface IVpc
id
- This parameter is required.options
- This parameter is required.public InterfaceVpcEndpoint addInterfaceEndpoint(java.lang.String id, InterfaceVpcEndpointOptions options)
addInterfaceEndpoint
in interface IVpc
id
- This parameter is required.options
- This parameter is required.@Deprecated public GatewayVpcEndpoint addS3Endpoint(java.lang.String id, java.util.List<SubnetSelection> subnets)
id
- This parameter is required.subnets
- @Deprecated public GatewayVpcEndpoint addS3Endpoint(java.lang.String id)
id
- This parameter is required.public VpnConnection addVpnConnection(java.lang.String id, VpnConnectionOptions options)
addVpnConnection
in interface IVpc
id
- This parameter is required.options
- This parameter is required.public void enableVpnGateway(EnableVpnGatewayOptions options)
enableVpnGateway
in interface IVpc
options
- This parameter is required.protected java.util.List<ISubnet> selectSubnetObjects(SubnetSelection selection)
selection
- protected java.util.List<ISubnet> selectSubnetObjects()
public SelectedSubnets selectSubnets(SubnetSelection selection)
selectSubnets
in interface IVpc
selection
- public SelectedSubnets selectSubnets()
selectSubnets
in interface IVpc
public java.util.List<java.lang.String> getAvailabilityZones()
getAvailabilityZones
in interface IVpc
public java.lang.Boolean getDnsHostnamesEnabled()
public java.lang.Boolean getDnsSupportEnabled()
public IDependable getInternetConnectivityEstablished()
getInternetConnectivityEstablished
in interface IVpc
public java.util.List<ISubnet> getIsolatedSubnets()
getIsolatedSubnets
in interface IVpc
@Deprecated protected java.util.List<IConstruct> getNatDependencies()
public java.util.List<ISubnet> getPrivateSubnets()
getPrivateSubnets
in interface IVpc
public java.util.List<ISubnet> getPublicSubnets()
getPublicSubnets
in interface IVpc
public java.lang.String getVpcArn()
public java.lang.String getVpcCidrBlock()
getVpcCidrBlock
in interface IVpc
public java.util.List<java.lang.String> getVpcCidrBlockAssociations()
public java.lang.String getVpcDefaultNetworkAcl()
public java.lang.String getVpcDefaultSecurityGroup()
public java.lang.String getVpcId()
public java.util.List<java.lang.String> getVpcIpv6CidrBlocks()
public java.lang.String getInternetGatewayId()
Note that in case the VPC is configured only
with ISOLATED subnets, this attribute will be undefined
.
public java.lang.String getVpnGatewayId()
getVpnGatewayId
in interface IVpc
protected java.lang.Boolean getIncompleteSubnetDefinition()
protected void setIncompleteSubnetDefinition(java.lang.Boolean value)