@Generated(value="jsii-pacmak/1.67.0 (build 2c027f5)", date="2022-09-19T20:26:38.507Z") @Stability(value=Stable) 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:
// Example automatically generated from non-compiling source. May contain errors.
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_EGRESS)
.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. |
software.amazon.jsii.JsiiObject.InitializationModeIVpc.Jsii$Default, IVpc.Jsii$Proxy| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_CIDR_RANGE
The default CIDR range used when creating VPCs.
|
static List<SubnetConfiguration> |
DEFAULT_SUBNETS
The default subnet configuration.
|
static List<SubnetConfiguration> |
DEFAULT_SUBNETS_NO_NAT
The default subnet configuration if natGateways specified to be 0.
|
| Modifier | Constructor and Description |
|---|---|
|
Vpc(software.constructs.Construct scope,
String id)
Vpc creates a VPC that spans a whole region.
|
|
Vpc(software.constructs.Construct scope,
String id,
VpcProps props)
Vpc creates a VPC that spans a whole region.
|
protected |
Vpc(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) |
protected |
Vpc(software.amazon.jsii.JsiiObjectRef objRef) |
| Modifier and Type | Method and Description |
|---|---|
ClientVpnEndpoint |
addClientVpnEndpoint(String id,
ClientVpnEndpointOptions options)
Adds a new client VPN endpoint to this VPC.
|
FlowLog |
addFlowLog(String id)
Adds a new flow log to this VPC.
|
FlowLog |
addFlowLog(String id,
FlowLogOptions options)
Adds a new flow log to this VPC.
|
GatewayVpcEndpoint |
addGatewayEndpoint(String id,
GatewayVpcEndpointOptions options)
Adds a new gateway endpoint to this VPC.
|
InterfaceVpcEndpoint |
addInterfaceEndpoint(String id,
InterfaceVpcEndpointOptions options)
Adds a new interface endpoint to this VPC.
|
VpnConnection |
addVpnConnection(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,
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,
String id,
VpcAttributes attrs)
Import a VPC by supplying all attributes directly.
|
List<String> |
getAvailabilityZones()
AZs for this VPC.
|
Boolean |
getDnsHostnamesEnabled()
Indicates if instances launched in this VPC will have public DNS hostnames.
|
Boolean |
getDnsSupportEnabled()
Indicates if DNS support is enabled for this VPC.
|
protected Boolean |
getIncompleteSubnetDefinition()
If this is set to true, don't error out on trying to select subnets.
|
software.constructs.IDependable |
getInternetConnectivityEstablished()
Dependencies for internet connectivity.
|
String |
getInternetGatewayId()
Internet Gateway for the VPC.
|
List<ISubnet> |
getIsolatedSubnets()
List of isolated subnets in this VPC.
|
List<ISubnet> |
getPrivateSubnets()
List of private subnets in this VPC.
|
List<ISubnet> |
getPublicSubnets()
List of public subnets in this VPC.
|
String |
getVpcArn()
Arn of this VPC.
|
String |
getVpcCidrBlock()
CIDR range for this VPC.
|
List<String> |
getVpcCidrBlockAssociations() |
String |
getVpcDefaultNetworkAcl() |
String |
getVpcDefaultSecurityGroup() |
String |
getVpcId()
Identifier for this VPC.
|
List<String> |
getVpcIpv6CidrBlocks() |
String |
getVpnGatewayId()
Returns the id of the VPN Gateway (if enabled).
|
protected List<ISubnet> |
selectSubnetObjects()
Return the subnets appropriate for the placement strategy.
|
protected 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(Boolean value)
If this is set to true, don't error out on trying to select subnets.
|
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResourcejsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitapplyRemovalPolicy, getEnv, getStack@Stability(value=Stable) public static final 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' })
@Stability(value=Stable) public static final List<SubnetConfiguration> DEFAULT_SUBNETS
1 Public and 1 Private subnet per AZ evenly split
@Stability(value=Stable) public static final 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)
@Stability(value=Stable)
public Vpc(@NotNull
software.constructs.Construct scope,
@NotNull
String id,
@Nullable
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 - @Stability(value=Stable)
public Vpc(@NotNull
software.constructs.Construct scope,
@NotNull
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.@Stability(value=Stable) @NotNull public static IVpc fromLookup(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull 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.@Stability(value=Stable) @NotNull public static IVpc fromVpcAttributes(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull 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.@Stability(value=Stable) @NotNull public ClientVpnEndpoint addClientVpnEndpoint(@NotNull String id, @NotNull ClientVpnEndpointOptions options)
addClientVpnEndpoint in interface IVpcid - This parameter is required.options - This parameter is required.@Stability(value=Stable) @NotNull public FlowLog addFlowLog(@NotNull String id, @Nullable FlowLogOptions options)
addFlowLog in interface IVpcid - This parameter is required.options - @Stability(value=Stable) @NotNull public FlowLog addFlowLog(@NotNull String id)
addFlowLog in interface IVpcid - This parameter is required.@Stability(value=Stable) @NotNull public GatewayVpcEndpoint addGatewayEndpoint(@NotNull String id, @NotNull GatewayVpcEndpointOptions options)
addGatewayEndpoint in interface IVpcid - This parameter is required.options - This parameter is required.@Stability(value=Stable) @NotNull public InterfaceVpcEndpoint addInterfaceEndpoint(@NotNull String id, @NotNull InterfaceVpcEndpointOptions options)
addInterfaceEndpoint in interface IVpcid - This parameter is required.options - This parameter is required.@Stability(value=Stable) @NotNull public VpnConnection addVpnConnection(@NotNull String id, @NotNull VpnConnectionOptions options)
addVpnConnection in interface IVpcid - This parameter is required.options - This parameter is required.@Stability(value=Stable)
public void enableVpnGateway(@NotNull
EnableVpnGatewayOptions options)
enableVpnGateway in interface IVpcoptions - This parameter is required.@Stability(value=Stable) @NotNull protected List<ISubnet> selectSubnetObjects(@Nullable SubnetSelection selection)
selection - @Stability(value=Stable) @NotNull protected List<ISubnet> selectSubnetObjects()
@Stability(value=Stable) @NotNull public SelectedSubnets selectSubnets(@Nullable SubnetSelection selection)
selectSubnets in interface IVpcselection - @Stability(value=Stable) @NotNull public SelectedSubnets selectSubnets()
selectSubnets in interface IVpc@Stability(value=Stable) @NotNull public List<String> getAvailabilityZones()
getAvailabilityZones in interface IVpc@Stability(value=Stable) @NotNull public Boolean getDnsHostnamesEnabled()
@Stability(value=Stable) @NotNull public Boolean getDnsSupportEnabled()
@Stability(value=Stable) @NotNull public software.constructs.IDependable getInternetConnectivityEstablished()
getInternetConnectivityEstablished in interface IVpc@Stability(value=Stable) @NotNull public List<ISubnet> getIsolatedSubnets()
getIsolatedSubnets in interface IVpc@Stability(value=Stable) @NotNull public List<ISubnet> getPrivateSubnets()
getPrivateSubnets in interface IVpc@Stability(value=Stable) @NotNull public List<ISubnet> getPublicSubnets()
getPublicSubnets in interface IVpc@Stability(value=Stable) @NotNull public String getVpcArn()
@Stability(value=Stable) @NotNull public String getVpcCidrBlock()
getVpcCidrBlock in interface IVpc@Stability(value=Stable) @NotNull public List<String> getVpcCidrBlockAssociations()
@Stability(value=Stable) @NotNull public String getVpcDefaultNetworkAcl()
@Stability(value=Stable) @NotNull public String getVpcDefaultSecurityGroup()
@Stability(value=Stable) @NotNull public String getVpcId()
@Stability(value=Stable) @Nullable public String getInternetGatewayId()
Note that in case the VPC is configured only
with ISOLATED subnets, this attribute will be undefined.
@Stability(value=Stable) @Nullable public String getVpnGatewayId()
getVpnGatewayId in interface IVpc@Stability(value=Stable) @NotNull protected Boolean getIncompleteSubnetDefinition()
@Stability(value=Stable)
protected void setIncompleteSubnetDefinition(@NotNull
Boolean value)
Copyright © 2022. All rights reserved.