# 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.

Obtainable from: SubnetFilter.availabilityZones, SubnetFilter.byCidrMask, SubnetFilter.byCidrRanges, SubnetFilter.byIds, SubnetFilter.containsIpAddresses, SubnetFilter.onePerAz

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

## Example

TypeScript:

```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']);
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_ec2 as ec2

subnet_filter = ec2.SubnetFilter.availability_zones(["availabilityZones"])
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.ec2.*;

SubnetFilter subnetFilter = SubnetFilter.availabilityZones(List.of("availabilityZones"));
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.EC2;

var subnetFilter = SubnetFilter.AvailabilityZones(new [] { "availabilityZones" });
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

subnetFilter := awscdk.Aws_ec2.SubnetFilter_AvailabilityZones([]*string{
	jsii.String("availabilityZones"),
})
```

## Initializer

TypeScript:

```ts
new SubnetFilter()
```

Python:

```python
SubnetFilter()
```

Java:

```java
new SubnetFilter()
```

C# / .NET:

```csharp
new SubnetFilter()
```

Golang:

```go
NewSubnetFilter()
```

## 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.
