# SelectedSubnets

Result of selecting a subset of subnets from a VPC.

Returned by: [IVpc.selectSubnets](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html#selectsubnets)

- 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#L441)
- Type last changed: v2.9.0 · 26 Jan 2022

## Example

TypeScript:

```ts
const vpc = new ec2.Vpc(this, 'VpcWithExplicitAzs', {
  availabilityZones: ['us-east-1a', 'us-east-1b'],
  natGateways: 0,
  subnetConfiguration: [{
    name: 'Application',
    subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
  }],
});

const selectedSubnets = vpc.selectSubnets({
  subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
  availabilityZones: ['us-east-1a'],
});
```

Python:

```python
vpc = ec2.Vpc(self, "VpcWithExplicitAzs",
    availability_zones=["us-east-1a", "us-east-1b"],
    nat_gateways=0,
    subnet_configuration=[ec2.SubnetConfiguration(
        name="Application",
        subnet_type=ec2.SubnetType.PRIVATE_ISOLATED
    )]
)

selected_subnets = vpc.select_subnets(
    subnet_type=ec2.SubnetType.PRIVATE_ISOLATED,
    availability_zones=["us-east-1a"]
)
```

Java:

```java
Vpc vpc = Vpc.Builder.create(this, "VpcWithExplicitAzs")
        .availabilityZones(List.of("us-east-1a", "us-east-1b"))
        .natGateways(0)
        .subnetConfiguration(List.of(SubnetConfiguration.builder()
                .name("Application")
                .subnetType(SubnetType.PRIVATE_ISOLATED)
                .build()))
        .build();

SelectedSubnets selectedSubnets = vpc.selectSubnets(SubnetSelection.builder()
        .subnetType(SubnetType.PRIVATE_ISOLATED)
        .availabilityZones(List.of("us-east-1a"))
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var vpc = new Vpc(this, "VpcWithExplicitAzs", new VpcProps {
    AvailabilityZones = new [] { "us-east-1a", "us-east-1b" },
    NatGateways = 0,
    SubnetConfiguration = new [] { new SubnetConfiguration {
        Name = "Application",
        SubnetType = SubnetType.PRIVATE_ISOLATED
    } }
});

var selectedSubnets = vpc.SelectSubnets(new SubnetSelection {
    SubnetType = SubnetType.PRIVATE_ISOLATED,
    AvailabilityZones = new [] { "us-east-1a" }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
vpc := ec2.NewVpc(this, jsii.String("VpcWithExplicitAzs"), &VpcProps{
	AvailabilityZones: []*string{
		jsii.String("us-east-1a"),
		jsii.String("us-east-1b"),
	},
	NatGateways: jsii.Number(0),
	SubnetConfiguration: []SubnetConfiguration{
		&SubnetConfiguration{
			Name: jsii.String("Application"),
			SubnetType: ec2.SubnetType_PRIVATE_ISOLATED,
		},
	},
})

selectedSubnets := vpc.selectSubnets(&SubnetSelection{
	SubnetType: ec2.SubnetType_PRIVATE_ISOLATED,
	AvailabilityZones: []*string{
		jsii.String("us-east-1a"),
	},
})
```

## Properties

- `availabilityZones`: string[] (required) — The respective AZs of each subnet.

- `hasPublic`: boolean (required) — Whether any of the given subnets are from the VPC's public subnets.

- `internetConnectivityEstablished`: [IDependable](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.IDependable.html) (required) — Dependency representing internet connectivity for these subnets.

- `isPendingLookup`: boolean = false — The subnet selection is not actually real yet.

  If this value is true, don't validate anything about the subnets. The count
  or identities are not known yet, and the validation will most likely fail
  which will prevent a successful lookup.

- `subnetIds`: string[] (required) — The subnet IDs.

- `subnets`: [ISubnet](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISubnet.html)[] (required) — Selected subnet objects.
