VpcProps

class aws_cdk.aws_ec2.VpcProps(*, availability_zones=None, cidr=None, create_internet_gateway=None, default_instance_tenancy=None, enable_dns_hostnames=None, enable_dns_support=None, flow_logs=None, gateway_endpoints=None, ip_addresses=None, ip_protocol=None, ipv6_addresses=None, max_azs=None, nat_gateway_provider=None, nat_gateways=None, nat_gateway_subnets=None, reserved_azs=None, restrict_default_security_group=None, subnet_configuration=None, vpc_name=None, vpn_connections=None, vpn_gateway=None, vpn_gateway_asn=None, vpn_route_propagation=None)

Bases: object

Configuration for Vpc.

Parameters:
  • availability_zones (Optional[Sequence[str]]) – Availability zones this VPC spans. Specify this option only if you do not specify maxAzs. Default: - a subset of AZs of the stack

  • cidr (Optional[str]) – (deprecated) The CIDR range to use for the VPC, e.g. ‘10.0.0.0/16’. Should be a minimum of /28 and maximum size of /16. The range will be split across all subnets per Availability Zone. Default: Vpc.DEFAULT_CIDR_RANGE

  • create_internet_gateway (Optional[bool]) – If set to false then disable the creation of the default internet gateway. Default: true

  • default_instance_tenancy (Optional[DefaultInstanceTenancy]) – 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: DefaultInstanceTenancy.Default (shared) tenancy

  • enable_dns_hostnames (Optional[bool]) – 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. Default: true

  • enable_dns_support (Optional[bool]) – Indicates whether the DNS resolution is supported for the VPC. 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. Default: true

  • flow_logs (Optional[Mapping[str, Union[FlowLogOptions, Dict[str, Any]]]]) – Flow logs to add to this VPC. Default: - No flow logs.

  • gateway_endpoints (Optional[Mapping[str, Union[GatewayVpcEndpointOptions, Dict[str, Any]]]]) – Gateway endpoints to add to this VPC. Default: - None.

  • ip_addresses (Optional[IIpAddresses]) – 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. Default: ec2.IpAddresses.cidr

  • ip_protocol (Optional[IpProtocol]) – The protocol of the vpc. Options are IPv4 only or dual stack. Default: IpProtocol.IPV4_ONLY

  • ipv6_addresses (Optional[IIpv6Addresses]) – The Provider to use to allocate IPv6 Space to your VPC. Options include amazon provided CIDR block. Note this is specific to IPv6 addresses. Default: Ipv6Addresses.amazonProvided

  • max_azs (Union[int, float, None]) – Define the maximum number of AZs to use in this region. 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. Default: 3

  • nat_gateway_provider (Optional[NatProvider]) – What type of NAT provider to use. Select between NAT gateways or NAT instances. NAT gateways may not be available in all AWS regions. Default: NatProvider.gateway()

  • nat_gateways (Union[int, float, None]) – The number of NAT Gateways/Instances to create. 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

  • nat_gateway_subnets (Union[SubnetSelection, Dict[str, Any], None]) – 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. Default: - All public subnets.

  • reserved_azs (Union[int, float, None]) – Define the number of AZs to reserve. When specified, the IP space is reserved for the azs but no actual resources are provisioned. Default: 0

  • restrict_default_security_group (Optional[bool]) – If set to true then the default inbound & outbound rules will be removed from the default security group. Default: true if @aws-cdk/aws-ec2:restrictDefaultSecurityGroup’ is enabled, false otherwise

  • subnet_configuration (Optional[Sequence[Union[SubnetConfiguration, Dict[str, Any]]]]) – Configure the subnets to build for each AZ. 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:: 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.

  • vpc_name (Optional[str]) – 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 Default: this.node.path

  • vpn_connections (Optional[Mapping[str, Union[VpnConnectionOptions, Dict[str, Any]]]]) – VPN connections to this VPC. Default: - No connections.

  • vpn_gateway (Optional[bool]) – Indicates whether a VPN gateway should be created and attached to this VPC. Default: - true when vpnGatewayAsn or vpnConnections is specified

  • vpn_gateway_asn (Union[int, float, None]) – The private Autonomous System Number (ASN) for the VPN gateway. Default: - Amazon default ASN.

  • vpn_route_propagation (Optional[Sequence[Union[SubnetSelection, Dict[str, Any]]]]) – Where to propagate VPN routes. 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.

ExampleMetadata:

infused

Example:

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
)

Attributes

availability_zones

Availability zones this VPC spans.

Specify this option only if you do not specify maxAzs.

Default:
  • a subset of AZs of the stack

cidr

(deprecated) The CIDR range to use for the VPC, e.g. ‘10.0.0.0/16’.

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

Default:

Vpc.DEFAULT_CIDR_RANGE

Deprecated:

Use ipAddresses instead

Stability:

deprecated

create_internet_gateway

If set to false then disable the creation of the default internet gateway.

Default:

true

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

Default:

DefaultInstanceTenancy.Default (shared) tenancy

enable_dns_hostnames

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.

Default:

true

enable_dns_support

Indicates whether the DNS resolution is supported for the VPC.

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.

Default:

true

flow_logs

Flow logs to add to this VPC.

Default:
  • No flow logs.

gateway_endpoints

Gateway endpoints to add to this VPC.

Default:
  • None.

ip_addresses

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.

Default:

ec2.IpAddresses.cidr

ip_protocol

The protocol of the vpc.

Options are IPv4 only or dual stack.

Default:

IpProtocol.IPV4_ONLY

ipv6_addresses

The Provider to use to allocate IPv6 Space to your VPC.

Options include amazon provided CIDR block.

Note this is specific to IPv6 addresses.

Default:

Ipv6Addresses.amazonProvided

max_azs

Define the maximum number of AZs to use in this region.

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.

Default:

3

nat_gateway_provider

What type of NAT provider to use.

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

Default:

NatProvider.gateway()

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

Default:
  • All public subnets.

nat_gateways

The number of NAT Gateways/Instances to create.

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

reserved_azs

Define the number of AZs to reserve.

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

Default:

0

restrict_default_security_group

If set to true then the default inbound & outbound rules will be removed from the default security group.

Default:

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

subnet_configuration

Configure the subnets to build for each AZ.

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:

ec2.Vpc(self, "VPC",
    subnet_configuration=[ec2.SubnetConfiguration(
        cidr_mask=24,
        name="ingress",
        subnet_type=ec2.SubnetType.PUBLIC
    ), ec2.SubnetConfiguration(
        cidr_mask=24,
        name="application",
        subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS
    ), ec2.SubnetConfiguration(
        cidr_mask=28,
        name="rds",
        subnet_type=ec2.SubnetType.PRIVATE_ISOLATED
    )
    ]
)
Default:

  • The VPC CIDR will be evenly divided between 1 public and 1

private subnet per AZ.

vpc_name

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

Default:

this.node.path

vpn_connections

VPN connections to this VPC.

Default:
  • No connections.

vpn_gateway

Indicates whether a VPN gateway should be created and attached to this VPC.

Default:
  • true when vpnGatewayAsn or vpnConnections is specified

vpn_gateway_asn

The private Autonomous System Number (ASN) for the VPN gateway.

Default:
  • Amazon default ASN.

vpn_route_propagation

Where to propagate VPN routes.

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.