IpAddresses

class aws_cdk.aws_ec2.IpAddresses(*args: Any, **kwargs)

Bases: object

An abstract Provider of IpAddresses.

Note this is specific to the IPv4 CIDR.

ExampleMetadata:

infused

Example:

vpc = ec2.Vpc(self, "TheVPC",
    # 'IpAddresses' configures the IP range and size of the entire VPC.
    # The IP space will be divided based on configuration for the subnets.
    ip_addresses=ec2.IpAddresses.cidr("10.0.0.0/21"),

    # 'maxAzs' configures the maximum number of availability zones to use.
    # If you want to specify the exact availability zones you want the VPC
    # to use, use `availabilityZones` instead.
    max_azs=3,

    # 'subnetConfiguration' specifies the "subnet groups" to create.
    # Every subnet group will have a subnet for each AZ, so this
    # configuration will create `3 groups × 3 AZs = 9` subnets.
    subnet_configuration=[ec2.SubnetConfiguration(
        # 'subnetType' controls Internet access, as described above.
        subnet_type=ec2.SubnetType.PUBLIC,

        # 'name' is used to name this particular subnet group. You will have to
        # use the name for subnet selection if you have more than one subnet
        # group of the same type.
        name="Ingress",

        # 'cidrMask' specifies the IP addresses in the range of of individual
        # subnets in the group. Each of the subnets in this group will contain
        # `2^(32 address bits - 24 subnet bits) - 2 reserved addresses = 254`
        # usable IP addresses.
        #
        # If 'cidrMask' is left out the available address space is evenly
        # divided across the remaining subnet groups.
        cidr_mask=24
    ), ec2.SubnetConfiguration(
        cidr_mask=24,
        name="Application",
        subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS
    ), ec2.SubnetConfiguration(
        cidr_mask=28,
        name="Database",
        subnet_type=ec2.SubnetType.PRIVATE_ISOLATED,

        # 'reserved' can be used to reserve IP address space. No resources will
        # be created for this subnet, but the IP range will be kept available for
        # future creation of this subnet, or even for future subdivision.
        reserved=True
    )
    ]
)

Static Methods

classmethod aws_ipam_allocation(*, ipv4_ipam_pool_id, ipv4_netmask_length, default_subnet_ipv4_netmask_length=None)

Used to provide centralized Ip Address Management services for your VPC.

Uses VPC CIDR allocations from AWS IPAM

Note this is specific to the IPv4 CIDR.

Parameters:
  • ipv4_ipam_pool_id (str) – Ipam Pool Id for ipv4 allocation.

  • ipv4_netmask_length (Union[int, float]) – Netmask length for Vpc.

  • default_subnet_ipv4_netmask_length (Union[int, float, None]) – Default length for Subnet ipv4 Network mask. Specify this option only if you do not specify all Subnets using SubnetConfiguration with a cidrMask Default: - Default ipv4 Subnet Mask for subnets in Vpc

See:

https://docs.aws.amazon.com/vpc/latest/ipam/what-it-is-ipam.html

Return type:

IIpAddresses

classmethod cidr(cidr_block)

Used to provide local Ip Address Management services for your VPC.

VPC CIDR is supplied at creation and subnets are calculated locally

Note this is specific to the IPv4 CIDR.

Parameters:

cidr_block (str) –

Return type:

IIpAddresses