# SubnetFilter

Contains logic which chooses a set of subnets from a larger list, in conjunction with SubnetSelection, to determine where to place AWS resources such as VPC endpoints, EC2 instances, etc.

- Source: [`aws-ec2/lib/subnet.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-ec2/lib/subnet.ts#L10)
- Type last changed: v2.101.0 · 13 Oct 2023

## Example

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_ec2 as ec2 } from 'aws-cdk-lib';
const subnetFilter = ec2.SubnetFilter.availabilityZones(['availabilityZones']);
```

## Initializer

```ts
new SubnetFilter()
```

## Methods

- `availabilityZones(availabilityZones: string[]): SubnetFilter // chainable` (static) — Chooses subnets which are in one of the given availability zones.

- `byCidrMask(mask: number): SubnetFilter // chainable` (static) — Chooses subnets which have the provided CIDR netmask.

- `byCidrRanges(cidrs: string[]): SubnetFilter // chainable` (static) — Chooses subnets which are inside any of the specified CIDR range.

  **Parameters**

  - `cidrs` — List of CIDR ranges to filter subnets from.

- `byIds(subnetIds: string[]): SubnetFilter // chainable` (static) — Chooses subnets by id.

- `containsIpAddresses(ipv4addrs: string[]): SubnetFilter // chainable` (static) — Chooses subnets which contain any of the specified IP addresses.

- `onePerAz(): SubnetFilter // chainable` (static) — Chooses subnets such that there is at most one per availability zone.

- `selectSubnets(_subnets: ISubnet[]): ISubnet[]` — Executes the subnet filtering logic, returning a filtered set of subnets.
