# SubnetIpv4IpamAllocation

Allocation of a subnet's IPv4 CIDR block from an Amazon VPC IP Address Manager (IPAM) pool.

- Source: [`aws-ec2/lib/vpc.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts#L2103)
- Type last changed: v2.278.0 · 20 Nov 2026

## Example

TypeScript:

```ts
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,
  },
});
```

Python:

```python
# 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
    )
)
```

Java:

```java
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();
```

C# / .NET:

```csharp
// 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
    }
});
```

Golang:

```go
// 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

- `ipamPool`: [IIPAMPoolRef](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_ec2.IIPAMPoolRef.html) (required) — The IPAM pool from which the CIDR block is allocated at deploy time.

  The pool must be a resource planning pool for the VPC the subnet belongs to (its
  `sourceResource` is the VPC), and the allocated CIDR block must lie within the CIDR of
  that VPC. Pools in a private scope require the IPAM Advanced Tier.
  To reference a pool that is not defined in this app, use `CfnIPAMPool.fromIpamPoolId()`.

- `netmaskLength`: number (required) — The netmask length of the CIDR block to allocate from the pool.

  Must be between 16 and 28 (inclusive), the sizes allowed for an IPv4 subnet.
