SubnetProps Struct
Specify configuration parameters for a VPC subnet.
| Source | aws-ec2/lib/vpc.ts |
|---|---|
| Type last changed |
Example
declare const vpc: ec2.Vpc;
declare const ipam: ec2.CfnIPAM;
const pool = new ec2.CfnIPAMPool(this, 'SubnetPool', {
addressFamily: 'ipv4',
ipamScopeId: ipam.attrPrivateDefaultScopeId,
locale: this.region,
sourceResource: {
resourceId: vpc.vpcId,
resourceOwner: this.account,
resourceRegion: this.region,
resourceType: 'vpc',
},
provisionedCidrs: [{ cidr: vpc.vpcCidrBlock }],
});
const subnet = new ec2.Subnet(this, 'IpamSubnet', {
vpcId: vpc.vpcId,
availabilityZone: vpc.availabilityZones[0],
ipv4IpamAllocation: {
ipamPool: pool,
netmaskLength: 24,
},
});
# vpc: ec2.Vpc
# ipam: ec2.CfnIPAM
pool = ec2.CfnIPAMPool(self, "SubnetPool",
address_family="ipv4",
ipam_scope_id=ipam.attr_private_default_scope_id,
locale=self.region,
source_resource=ec2.CfnIPAMPool.SourceResourceProperty(
resource_id=vpc.vpc_id,
resource_owner=self.account,
resource_region=self.region,
resource_type="vpc"
),
provisioned_cidrs=[ec2.CfnIPAMPool.ProvisionedCidrProperty(cidr=vpc.vpc_cidr_block)]
)
subnet = ec2.Subnet(self, "IpamSubnet",
vpc_id=vpc.vpc_id,
availability_zone=vpc.availability_zones[0],
ipv4_ipam_allocation=ec2.SubnetIpv4IpamAllocation(
ipam_pool=pool,
netmask_length=24
)
)
Vpc vpc;
CfnIPAM ipam;
CfnIPAMPool pool = CfnIPAMPool.Builder.create(this, "SubnetPool")
.addressFamily("ipv4")
.ipamScopeId(ipam.getAttrPrivateDefaultScopeId())
.locale(this.region)
.sourceResource(SourceResourceProperty.builder()
.resourceId(vpc.getVpcId())
.resourceOwner(this.account)
.resourceRegion(this.region)
.resourceType("vpc")
.build())
.provisionedCidrs(List.of(ProvisionedCidrProperty.builder().cidr(vpc.getVpcCidrBlock()).build()))
.build();
Subnet subnet = Subnet.Builder.create(this, "IpamSubnet")
.vpcId(vpc.getVpcId())
.availabilityZone(vpc.getAvailabilityZones()[0])
.ipv4IpamAllocation(SubnetIpv4IpamAllocation.builder()
.ipamPool(pool)
.netmaskLength(24)
.build())
.build();
// Install: dotnet add package Amazon.CDK.Lib
Vpc vpc;
CfnIPAM ipam;
var pool = new CfnIPAMPool(this, "SubnetPool", new CfnIPAMPoolProps {
AddressFamily = "ipv4",
IpamScopeId = ipam.AttrPrivateDefaultScopeId,
Locale = Region,
SourceResource = new SourceResourceProperty {
ResourceId = vpc.VpcId,
ResourceOwner = Account,
ResourceRegion = Region,
ResourceType = "vpc"
},
ProvisionedCidrs = new [] { new ProvisionedCidrProperty { Cidr = vpc.VpcCidrBlock } }
});
var subnet = new Subnet(this, "IpamSubnet", new SubnetProps {
VpcId = vpc.VpcId,
AvailabilityZone = vpc.AvailabilityZones[0],
Ipv4IpamAllocation = new SubnetIpv4IpamAllocation {
IpamPool = pool,
NetmaskLength = 24
}
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc Vpc
var ipam CfnIPAM
pool := ec2.NewCfnIPAMPool(this, jsii.String("SubnetPool"), &CfnIPAMPoolProps{
AddressFamily: jsii.String("ipv4"),
IpamScopeId: ipam.attrPrivateDefaultScopeId,
Locale: this.Region,
SourceResource: &SourceResourceProperty{
ResourceId: vpc.VpcId,
ResourceOwner: this.Account,
ResourceRegion: this.*Region,
ResourceType: jsii.String("vpc"),
},
ProvisionedCidrs: []interface{}{
&ProvisionedCidrProperty{
Cidr: vpc.VpcCidrBlock,
},
},
})
subnet := ec2.NewSubnet(this, jsii.String("IpamSubnet"), &SubnetProps{
VpcId: vpc.*VpcId,
AvailabilityZone: vpc.AvailabilityZones[jsii.Number(0)],
Ipv4IpamAllocation: &SubnetIpv4IpamAllocation{
IpamPool: pool,
NetmaskLength: jsii.Number(24),
},
})
Properties
assignIpv6AddressOnCreationoptionalbooleanassign_ipv6_address_on_creationoptionalboolassignIpv6AddressOnCreationoptionalBooleanAssignIpv6AddressOnCreationoptionalboolAssignIpv6AddressOnCreationoptional*bool = false #If you specify AssignIpv6AddressOnCreation, you must also specify Ipv6CidrBlock.
availabilityZonestringavailability_zonestravailabilityZoneStringAvailabilityZonestringAvailabilityZone*string required #cidrBlockoptionalstringcidr_blockoptionalstrcidrBlockoptionalStringCidrBlockoptionalstringCidrBlockoptional*string #Default: the CIDR block is allocated from the IPAM pool given in ipv4IpamAllocation
Exactly one of cidrBlock and ipv4IpamAllocation must be specified.
ipv4IpamAllocationoptionalSubnetIpv4IpamAllocationipv4_ipam_allocationoptionalSubnetIpv4IpamAllocationipv4IpamAllocationoptionalSubnetIpv4IpamAllocationIpv4IpamAllocationoptionalSubnetIpv4IpamAllocationIpv4IpamAllocationoptionalSubnetIpv4IpamAllocation #Default: the subnet uses the concrete cidrBlock
notes
When set, ipv4CidrBlock resolves to a deploy-time attribute of the subnet instead of a concrete string, so SubnetFilter.byCidrMask(), SubnetFilter.byCidrRanges() and SubnetFilter.containsIpAddresses() cannot be used with this subnet.
Exactly one of cidrBlock and ipv4IpamAllocation must be specified.
ipv6CidrBlockoptionalstringipv6_cidr_blockoptionalstripv6CidrBlockoptionalStringIpv6CidrBlockoptionalstringIpv6CidrBlockoptional*string #Default: no IPv6 CIDR block.
If you specify AssignIpv6AddressOnCreation, you must also specify Ipv6CidrBlock.
mapPublicIpOnLaunchoptionalbooleanmap_public_ip_on_launchoptionalboolmapPublicIpOnLaunchoptionalBooleanMapPublicIpOnLaunchoptionalboolMapPublicIpOnLaunchoptional*bool #Default: true in Subnet.Public, false in Subnet.Private or Subnet.Isolated.