Skip to content
v2.274.0

Vpc L2 construct ​

Define an AWS Virtual Private Cloud.

See the package-level documentation of this package for an overview of the various dimensions in which you can configure your VPC.

For example:

ts
const vpc = new ec2.Vpc(this, 'TheVPC', {
  ipAddresses: ec2.IpAddresses.cidr('10.0.0.0/16'),
})

// Iterate the private subnets
const selection = vpc.selectSubnets({
  subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS
});

for (const subnet of selection.subnets) {
  // ...
}

Example ​

ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';

const vpc = new ec2.Vpc(this, 'Vpc', {
  ipAddresses: ec2.IpAddresses.cidr('10.0.0.0/16')
});

const vpcConnector = new apprunner.VpcConnector(this, 'VpcConnector', {
  vpc,
  vpcSubnets: vpc.selectSubnets({ subnetType: ec2.SubnetType.PUBLIC }),
  vpcConnectorName: 'MyVpcConnector',
});

new apprunner.Service(this, 'Service', {
  source: apprunner.Source.fromEcrPublic({
    imageConfiguration: { port: 8000 },
    imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest',
  }),
  vpcConnector,
});
python
import aws_cdk.aws_ec2 as ec2


vpc = ec2.Vpc(self, "Vpc",
    ip_addresses=ec2.IpAddresses.cidr("10.0.0.0/16")
)

vpc_connector = apprunner.VpcConnector(self, "VpcConnector",
    vpc=vpc,
    vpc_subnets=vpc.select_subnets(subnet_type=ec2.SubnetType.PUBLIC),
    vpc_connector_name="MyVpcConnector"
)

apprunner.Service(self, "Service",
    source=apprunner.Source.from_ecr_public(
        image_configuration=apprunner.ImageConfiguration(port=8000),
        image_identifier="public.ecr.aws/aws-containers/hello-app-runner:latest"
    ),
    vpc_connector=vpc_connector
)
java
import software.amazon.awscdk.services.ec2.*;


Vpc vpc = Vpc.Builder.create(this, "Vpc")
        .ipAddresses(IpAddresses.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();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.EC2;


var vpc = new Vpc(this, "Vpc", new VpcProps {
    IpAddresses = IpAddresses.Cidr("10.0.0.0/16")
});

var vpcConnector = new VpcConnector(this, "VpcConnector", new VpcConnectorProps {
    Vpc = vpc,
    VpcSubnets = vpc.SelectSubnets(new SubnetSelection { SubnetType = SubnetType.PUBLIC }),
    VpcConnectorName = "MyVpcConnector"
});

new Service(this, "Service", new ServiceProps {
    Source = Source.FromEcrPublic(new EcrPublicProps {
        ImageConfiguration = new ImageConfiguration { Port = 8000 },
        ImageIdentifier = "public.ecr.aws/aws-containers/hello-app-runner:latest"
    }),
    VpcConnector = vpcConnector
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"


vpc := ec2.NewVpc(this, jsii.String("Vpc"), &VpcProps{
	IpAddresses: ec2.IpAddresses_Cidr(jsii.String("10.0.0.0/16")),
})

vpcConnector := apprunner.NewVpcConnector(this, jsii.String("VpcConnector"), &VpcConnectorProps{
	Vpc: Vpc,
	VpcSubnets: vpc.selectSubnets(&SubnetSelection{
		SubnetType: ec2.SubnetType_PUBLIC,
	}),
	VpcConnectorName: jsii.String("MyVpcConnector"),
})

apprunner.NewService(this, jsii.String("Service"), &ServiceProps{
	Source: apprunner.Source_FromEcrPublic(&EcrPublicProps{
		ImageConfiguration: &ImageConfiguration{
			Port: jsii.Number(8000),
		},
		ImageIdentifier: jsii.String("public.ecr.aws/aws-containers/hello-app-runner:latest"),
	}),
	VpcConnector: VpcConnector,
})

Initializer ​

ts
new Vpc(scope: Construct, id: string, props?: VpcProps)
python
Vpc(scope: Construct, id: str, props: typing.Optional[VpcProps] = None)
java
new Vpc(Construct scope, String id, VpcProps props)
csharp
new Vpc(Construct scope, string id, VpcProps? props = null)
go
NewVpc(Scope Construct, Id *string, Props VpcProps)

Construct Props ​

availabilityZonesstring[]availability_zonestyping.List[str]availabilityZonesList<String>AvailabilityZonesstring[]AvailabilityZones*[]*string= a subset of AZs of the stack#
Availability zones this VPC spans.

Specify this option only if you do not specify maxAzs.

cidrstringcidrstrcidrStringCidrstringCidr*string= Vpc.DEFAULT_CIDR_RANGEdeprecated#
Use ipAddresses instead

Should be a minimum of /28 and maximum size of /16. The range will be split across all subnets per Availability Zone.

createInternetGatewaybooleancreate_internet_gatewayboolcreateInternetGatewayBooleanCreateInternetGatewayboolCreateInternetGateway*bool= true#
If set to false then disable the creation of the default internet gateway.
defaultInstanceTenancyDefaultInstanceTenancydefault_instance_tenancyDefaultInstanceTenancydefaultInstanceTenancyDefaultInstanceTenancyDefaultInstanceTenancyDefaultInstanceTenancyDefaultInstanceTenancyDefaultInstanceTenancy= DefaultInstanceTenancy.Default (…#
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.

default

Default: DefaultInstanceTenancy.Default (shared) tenancy

enableDnsHostnamesbooleanenable_dns_hostnamesboolenableDnsHostnamesBooleanEnableDnsHostnamesboolEnableDnsHostnames*bool= true#
Indicates whether the instances launched in the VPC get public DNS hostnames.

If this attribute is true, instances in the VPC get public DNS hostnames, but only if the enableDnsSupport attribute is also set to true.

enableDnsSupportbooleanenable_dns_supportboolenableDnsSupportBooleanEnableDnsSupportboolEnableDnsSupport*bool= true#
Indicates whether the DNS resolution is supported for the VPC.
notes

If this attribute is false, the Amazon-provided DNS server in the VPC that resolves public DNS hostnames to IP addresses is not enabled. If this attribute is true, queries to the Amazon provided DNS server at the 169.254.169.253 IP address, or the reserved IP address at the base of the VPC IPv4 network range plus two will succeed.

flowLogs{ [key: string]: FlowLogOptions }flow_logstyping.Mapping[str, FlowLogOptions]flowLogsMap<String, FlowLogOptions>FlowLogsIDictionary<string, FlowLogOptions>FlowLogs*map[string]FlowLogOptions= No flow logs.#
Flow logs to add to this VPC.
gatewayEndpoints{ [key: string]: GatewayVpcEndpointOptions }gateway_endpointstyping.Mapping[str, GatewayVpcEndpointOptions]gatewayEndpointsMap<String, GatewayVpcEndpointOptions>GatewayEndpointsIDictionary<string, GatewayVpcEndpointOptions>GatewayEndpoints*map[string]GatewayVpcEndpointOptions= None.#
Gateway endpoints to add to this VPC.
ipAddressesIIpAddressesip_addressesIIpAddressesipAddressesIIpAddressesIpAddressesIIpAddressesIpAddressesIIpAddresses= ec2.IpAddresses.cidr#
The Provider to use to allocate IPv4 Space to your VPC.

Options include static allocation or from a pool.

Note this is specific to IPv4 addresses.

ipProtocolIpProtocolip_protocolIpProtocolipProtocolIpProtocolIpProtocolIpProtocolIpProtocolIpProtocol= IpProtocol.IPV4_ONLY#
The protocol of the vpc.

Options are IPv4 only or dual stack.

ipv6AddressesIIpv6Addressesipv6_addressesIIpv6Addressesipv6AddressesIIpv6AddressesIpv6AddressesIIpv6AddressesIpv6AddressesIIpv6Addresses= Ipv6Addresses.amazonProvided#
The Provider to use to allocate IPv6 Space to your VPC.

Options include amazon provided CIDR block.

Note this is specific to IPv6 addresses.

maxAzsnumbermax_azsint | floatmaxAzsNumberMaxAzsdoubleMaxAzs*float64= 3#
Define the maximum number of AZs to use in this region.
notes

If the region has more AZs than you want to use (for example, because of EIP limits), pick a lower number here. The AZs will be sorted and picked from the start of the list.

If you pick a higher number than the number of AZs in the region, all AZs in the region will be selected. To use "all AZs" available to your account, use a high number (such as 99).

Be aware that environment-agnostic stacks will be created with access to only 2 AZs, so to use more than 2 AZs, be sure to specify the account and region on your stack.

Specify this option only if you do not specify availabilityZones.

natGatewayProviderNatProvidernat_gateway_providerNatProvidernatGatewayProviderNatProviderNatGatewayProviderNatProviderNatGatewayProviderNatProvider= NatProvider.gateway()#
What type of NAT provider to use.

Select between NAT gateways or NAT instances. NAT gateways may not be available in all AWS regions.

natGatewaysnumbernat_gatewaysint | floatnatGatewaysNumberNatGatewaysdoubleNatGateways*float64= One NAT gateway/instance per Ava…#
The number of NAT Gateways/Instances to create.
notes · default

The type of NAT gateway or instance will be determined by the natGatewayProvider parameter.

You can set this number lower than the number of Availability Zones in your VPC in order to save on NAT cost. Be aware you may be charged for cross-AZ data traffic instead.

Default: One NAT gateway/instance per Availability Zone

natGatewaySubnetsSubnetSelectionnat_gateway_subnetsSubnetSelectionnatGatewaySubnetsSubnetSelectionNatGatewaySubnetsSubnetSelectionNatGatewaySubnetsSubnetSelection= All public subnets.#
Configures the subnets which will have NAT Gateways/Instances.

You can pick a specific group of subnets by specifying the group name; the picked subnets must be public subnets.

Only necessary if you have more than one public subnet group.

reservedAzsnumberreserved_azsint | floatreservedAzsNumberReservedAzsdoubleReservedAzs*float64= 0#
Define the number of AZs to reserve.

When specified, the IP space is reserved for the azs but no actual resources are provisioned.

restrictDefaultSecurityGroupbooleanrestrict_default_security_groupboolrestrictDefaultSecurityGroupBooleanRestrictDefaultSecurityGroupboolRestrictDefaultSecurityGroup*bool= true if '@aws-cdk/aws-ec2:restri…#
If set to true then the default inbound & outbound rules will be removed from the default security group.
default

Default: true if '@aws-cdk/aws-ec2:restrictDefaultSecurityGroup' is enabled, false otherwise

subnetConfigurationSubnetConfiguration[]subnet_configurationtyping.List[SubnetConfiguration]subnetConfigurationList<SubnetConfiguration>SubnetConfigurationSubnetConfiguration[]SubnetConfiguration*[]SubnetConfiguration= The VPC CIDR will be evenly divi…#
Configure the subnets to build for each AZ.
notes · default

Each entry in this list configures a Subnet Group; each group will contain a subnet for each Availability Zone.

For example, if you want 1 public subnet, 1 private subnet, and 1 isolated subnet in each AZ provide the following:

ts
new ec2.Vpc(this, 'VPC', {
  subnetConfiguration: [
     {
       cidrMask: 24,
       name: 'ingress',
       subnetType: ec2.SubnetType.PUBLIC,
     },
     {
       cidrMask: 24,
       name: 'application',
       subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS,
     },
     {
       cidrMask: 28,
       name: 'rds',
       subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
     }
  ]
});

Default: The VPC CIDR will be evenly divided between 1 public and 1 private subnet per AZ.

vpcNamestringvpc_namestrvpcNameStringVpcNamestringVpcName*string= this.node.path#
The VPC name.

Since the VPC resource doesn't support providing a physical name, the value provided here will be recorded in the Name tag

vpnConnections{ [key: string]: VpnConnectionOptions }vpn_connectionstyping.Mapping[str, VpnConnectionOptions]vpnConnectionsMap<String, VpnConnectionOptions>VpnConnectionsIDictionary<string, VpnConnectionOptions>VpnConnections*map[string]VpnConnectionOptions= No connections.#
VPN connections to this VPC.
vpnGatewaybooleanvpn_gatewayboolvpnGatewayBooleanVpnGatewayboolVpnGateway*bool= true when vpnGatewayAsn or vpnCo…#
Indicates whether a VPN gateway should be created and attached to this VPC.
default

Default: true when vpnGatewayAsn or vpnConnections is specified

vpnGatewayAsnnumbervpn_gateway_asnint | floatvpnGatewayAsnNumberVpnGatewayAsndoubleVpnGatewayAsn*float64= Amazon default ASN.#
The private Autonomous System Number (ASN) for the VPN gateway.
vpnRoutePropagationSubnetSelection[]vpn_route_propagationtyping.List[SubnetSelection]vpnRoutePropagationList<SubnetSelection>VpnRoutePropagationSubnetSelection[]VpnRoutePropagation*[]SubnetSelection= On the route tables associated w…#
Where to propagate VPN routes.
default

Default: On the route tables associated with private subnets. If no private subnets exists, isolated subnets are used. If no isolated subnets exists, public subnets are used.

Properties ​

availabilityZonesstring[]availability_zonestyping.List[str]availabilityZonesList<String>AvailabilityZonesstring[]AvailabilityZones*[]*stringrequired#
AZs for this VPC.
DEFAULT_CIDR_RANGEstringdefault_cidr_rangestrDEFAULT_CIDR_RANGEStringDEFAULT_CIDR_RANGEstringDEFAULT_CIDR_RANGE*stringrequiredstatic#
The default CIDR range used when creating VPCs.

This can be overridden using VpcProps when creating a VPCNetwork resource. e.g. new VpcResource(this, { cidr: '192.168.0.0./16' })

Note this is specific to the IPv4 CIDR.

DEFAULT_SUBNETSSubnetConfiguration[]default_subnetstyping.List[SubnetConfiguration]DEFAULT_SUBNETSList<SubnetConfiguration>DEFAULT_SUBNETSSubnetConfiguration[]DEFAULT_SUBNETS*[]SubnetConfigurationrequiredstatic#
The default subnet configuration.

1 Public and 1 Private subnet per AZ evenly split

DEFAULT_SUBNETS_NO_NATSubnetConfiguration[]default_subnets_no_nattyping.List[SubnetConfiguration]DEFAULT_SUBNETS_NO_NATList<SubnetConfiguration>DEFAULT_SUBNETS_NO_NATSubnetConfiguration[]DEFAULT_SUBNETS_NO_NAT*[]SubnetConfigurationrequiredstatic#
The default subnet configuration if natGateways specified to be 0.

1 Public and 1 Isolated Subnet per AZ evenly split

dnsHostnamesEnabledbooleandns_hostnames_enabledbooldnsHostnamesEnabledBooleanDnsHostnamesEnabledboolDnsHostnamesEnabled*boolrequired#
Indicates if instances launched in this VPC will have public DNS hostnames.
dnsSupportEnabledbooleandns_support_enabledbooldnsSupportEnabledBooleanDnsSupportEnabledboolDnsSupportEnabled*boolrequired#
Indicates if DNS support is enabled for this VPC.
The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

internetConnectivityEstablishedIDependableinternet_connectivity_establishedIDependableinternetConnectivityEstablishedIDependableInternetConnectivityEstablishedIDependableInternetConnectivityEstablishedIDependablerequired#
Dependencies for internet connectivity.
internetGatewayIdstringinternet_gateway_idstrinternetGatewayIdStringInternetGatewayIdstringInternetGatewayId*string#
Internet Gateway for the VPC.

Note that in case the VPC is configured only with ISOLATED subnets, this attribute will be undefined.

isolatedSubnetsISubnet[]isolated_subnetstyping.List[ISubnet]isolatedSubnetsList<ISubnet>IsolatedSubnetsISubnet[]IsolatedSubnets*[]ISubnetrequired#
List of isolated subnets in this VPC.
nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
privateSubnetsISubnet[]private_subnetstyping.List[ISubnet]privateSubnetsList<ISubnet>PrivateSubnetsISubnet[]PrivateSubnets*[]ISubnetrequired#
List of private subnets in this VPC.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
publicSubnetsISubnet[]public_subnetstyping.List[ISubnet]publicSubnetsList<ISubnet>PublicSubnetsISubnet[]PublicSubnets*[]ISubnetrequired#
List of public subnets in this VPC.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.
vpcArnstringvpc_arnstrvpcArnStringVpcArnstringVpcArn*stringrequired#
Arn of this VPC.
vpcCidrBlockstringvpc_cidr_blockstrvpcCidrBlockStringVpcCidrBlockstringVpcCidrBlock*stringrequired#
CIDR range for this VPC.
vpcCidrBlockAssociationsstring[]vpc_cidr_block_associationstyping.List[str]vpcCidrBlockAssociationsList<String>VpcCidrBlockAssociationsstring[]VpcCidrBlockAssociations*[]*stringrequired#
vpcDefaultNetworkAclstringvpc_default_network_aclstrvpcDefaultNetworkAclStringVpcDefaultNetworkAclstringVpcDefaultNetworkAcl*stringrequired#
vpcDefaultSecurityGroupstringvpc_default_security_groupstrvpcDefaultSecurityGroupStringVpcDefaultSecurityGroupstringVpcDefaultSecurityGroup*stringrequired#
vpcIdstringvpc_idstrvpcIdStringVpcIdstringVpcId*stringrequired#
Identifier for this VPC.
vpcIpv6CidrBlocksstring[]vpc_ipv6_cidr_blockstyping.List[str]vpcIpv6CidrBlocksList<String>VpcIpv6CidrBlocksstring[]VpcIpv6CidrBlocks*[]*stringrequired#
A reference to a VPC resource.
vpnGatewayIdstringvpn_gateway_idstrvpnGatewayIdStringVpnGatewayIdstringVpnGatewayId*string#
Returns the id of the VPN Gateway (if enabled).

Methods ​

addClientVpnEndpoint(id: string, options: ClientVpnEndpointOptions): ClientVpnEndpointdef add_client_vpn_endpoint(self, id: str, options: ClientVpnEndpointOptions) -> ClientVpnEndpointpublic ClientVpnEndpoint addClientVpnEndpoint(String id, ClientVpnEndpointOptions options)public ClientVpnEndpoint AddClientVpnEndpoint(string id, ClientVpnEndpointOptions options)func AddClientVpnEndpoint(Id *string, Options ClientVpnEndpointOptions) ClientVpnEndpoint#
Adds a new client VPN endpoint to this VPC.
addFlowLog(id: string, options?: FlowLogOptions): FlowLogdef add_flow_log(self, id: str, options: typing.Optional[FlowLogOptions] = None) -> FlowLogpublic FlowLog addFlowLog(String id, FlowLogOptions options)public FlowLog AddFlowLog(string id, FlowLogOptions? options = null)func AddFlowLog(Id *string, Options FlowLogOptions) FlowLog#
Adds a new flow log to this VPC.
addGatewayEndpoint(id: string, options: GatewayVpcEndpointOptions): GatewayVpcEndpointdef add_gateway_endpoint(self, id: str, options: GatewayVpcEndpointOptions) -> GatewayVpcEndpointpublic GatewayVpcEndpoint addGatewayEndpoint(String id, GatewayVpcEndpointOptions options)public GatewayVpcEndpoint AddGatewayEndpoint(string id, GatewayVpcEndpointOptions options)func AddGatewayEndpoint(Id *string, Options GatewayVpcEndpointOptions) GatewayVpcEndpoint#
Adds a new gateway endpoint to this VPC.
addInterfaceEndpoint(id: string, options: InterfaceVpcEndpointOptions): InterfaceVpcEndpointdef add_interface_endpoint(self, id: str, options: InterfaceVpcEndpointOptions) -> InterfaceVpcEndpointpublic InterfaceVpcEndpoint addInterfaceEndpoint(String id, InterfaceVpcEndpointOptions options)public InterfaceVpcEndpoint AddInterfaceEndpoint(string id, InterfaceVpcEndpointOptions options)func AddInterfaceEndpoint(Id *string, Options InterfaceVpcEndpointOptions) InterfaceVpcEndpoint#
Adds a new interface endpoint to this VPC.
addVpnConnection(id: string, options: VpnConnectionOptions): VpnConnectiondef add_vpn_connection(self, id: str, options: VpnConnectionOptions) -> VpnConnectionpublic VpnConnection addVpnConnection(String id, VpnConnectionOptions options)public VpnConnection AddVpnConnection(string id, VpnConnectionOptions options)func AddVpnConnection(Id *string, Options VpnConnectionOptions) VpnConnection#
Adds a new VPN connection to this VPC.
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

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).

enableVpnGateway(options: EnableVpnGatewayOptions): voiddef enable_vpn_gateway(self, options: EnableVpnGatewayOptions) -> Nonepublic void enableVpnGateway(EnableVpnGatewayOptions options)public void EnableVpnGateway(EnableVpnGatewayOptions options)func EnableVpnGateway(Options EnableVpnGatewayOptions)#
Adds a VPN Gateway to this VPC.
fromLookup(scope: Construct, id: string, options: VpcLookupOptions): IVpc@staticmethod def from_lookup(scope: Construct, id: str, options: VpcLookupOptions) -> IVpcpublic static IVpc fromLookup(Construct scope, String id, VpcLookupOptions options)public static IVpc FromLookup(Construct scope, string id, VpcLookupOptions options)func FromLookup(Scope Construct, Id *string, Options VpcLookupOptions) IVpcstatic#
Import an existing VPC by querying the AWS environment this stack is deployed to.
notes

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.

fromVpcAttributes(scope: Construct, id: string, attrs: VpcAttributes): IVpc@staticmethod def from_vpc_attributes(scope: Construct, id: str, attrs: VpcAttributes) -> IVpcpublic static IVpc fromVpcAttributes(Construct scope, String id, VpcAttributes attrs)public static IVpc FromVpcAttributes(Construct scope, string id, VpcAttributes attrs)func FromVpcAttributes(Scope Construct, Id *string, Attrs VpcAttributes) IVpcstatic#
Import a VPC by supplying all attributes directly.
notes

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.

isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
selectSubnets(selection?: SubnetSelection): SelectedSubnetsdef select_subnets(self, selection: typing.Optional[SubnetSelection] = None) -> SelectedSubnetspublic SelectedSubnets selectSubnets(SubnetSelection selection)public SelectedSubnets SelectSubnets(SubnetSelection? selection = null)func SelectSubnets(Selection SubnetSelection) SelectedSubnets#
Returns IDs of selected subnets.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.