IpAddresses Class
An abstract Provider of IpAddresses.
Note this is specific to the IPv4 CIDR.
| Source | aws-ec2/lib/ip-addresses.ts |
|---|---|
| Type last changed |
Example
ts
const vpc = new ec2.Vpc(this, 'TheVPC', {
// 'IpAddresses' configures the IP range and size of the entire VPC.
// The IP space will be divided based on configuration for the subnets.
ipAddresses: 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.
maxAzs: 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.
subnetConfiguration: [
{
// 'subnetType' controls Internet access, as described above.
subnetType: 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 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.
cidrMask: 24,
},
{
cidrMask: 24,
name: 'Application',
subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS,
},
{
cidrMask: 28,
name: 'Database',
subnetType: 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
}
],
});
python
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 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
)
]
)
java
Vpc vpc = Vpc.Builder.create(this, "TheVPC")
// 'IpAddresses' configures the IP range and size of the entire VPC.
// The IP space will be divided based on configuration for the subnets.
.ipAddresses(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.
.maxAzs(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.
.subnetConfiguration(List.of(SubnetConfiguration.builder()
// 'subnetType' controls Internet access, as described above.
.subnetType(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 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.
.cidrMask(24)
.build(), SubnetConfiguration.builder()
.cidrMask(24)
.name("Application")
.subnetType(SubnetType.PRIVATE_WITH_EGRESS)
.build(), SubnetConfiguration.builder()
.cidrMask(28)
.name("Database")
.subnetType(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)
.build()))
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
var vpc = new Vpc(this, "TheVPC", new VpcProps {
// 'IpAddresses' configures the IP range and size of the entire VPC.
// The IP space will be divided based on configuration for the subnets.
IpAddresses = 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.
MaxAzs = 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.
SubnetConfiguration = new [] { new SubnetConfiguration {
// 'subnetType' controls Internet access, as described above.
SubnetType = 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 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.
CidrMask = 24
}, new SubnetConfiguration {
CidrMask = 24,
Name = "Application",
SubnetType = SubnetType.PRIVATE_WITH_EGRESS
}, new SubnetConfiguration {
CidrMask = 28,
Name = "Database",
SubnetType = 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
} }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
vpc := ec2.NewVpc(this, jsii.String("TheVPC"), &VpcProps{
// 'IpAddresses' configures the IP range and size of the entire VPC.
// The IP space will be divided based on configuration for the subnets.
IpAddresses: ec2.IpAddresses_Cidr(jsii.String("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.
MaxAzs: jsii.Number(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.
SubnetConfiguration: []SubnetConfiguration{
&SubnetConfiguration{
// 'subnetType' controls Internet access, as described above.
SubnetType: 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: jsii.String("Ingress"),
// 'cidrMask' specifies the IP addresses in the range 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.
CidrMask: jsii.Number(24),
},
&SubnetConfiguration{
CidrMask: jsii.Number(24),
Name: jsii.String("Application"),
SubnetType: ec2.SubnetType_PRIVATE_WITH_EGRESS,
},
&SubnetConfiguration{
CidrMask: jsii.Number(28),
Name: jsii.String("Database"),
SubnetType: 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: jsii.Boolean(true),
},
},
})
Methods
awsIpamAllocation(props: AwsIpamProps): IIpAddresses@staticmethod def aws_ipam_allocation(props: AwsIpamProps) -> IIpAddressespublic static IIpAddresses awsIpamAllocation(AwsIpamProps props)public static IIpAddresses AwsIpamAllocation(AwsIpamProps props)func AwsIpamAllocation(Props AwsIpamProps) IIpAddresses static #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.
cidr(cidrBlock: string): IIpAddresses@staticmethod def cidr(cidr_block: str) -> IIpAddressespublic static IIpAddresses cidr(String cidrBlock)public static IIpAddresses Cidr(string cidrBlock)func Cidr(CidrBlock *string) IIpAddresses static #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.