Skip to content
v2.278.0

SelectedSubnets Struct ​

Result of selecting a subset of subnets from a VPC.

Example ​

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
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
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());
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" }
});
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 ​

availabilityZonesstring[]availability_zonestyping.List[str]availabilityZonesList<String>AvailabilityZonesstring[]AvailabilityZones*[]*string required #
The respective AZs of each subnet.
hasPublicbooleanhas_publicboolhasPublicBooleanHasPublicboolHasPublic*bool required #
Whether any of the given subnets are from the VPC's public subnets.
internetConnectivityEstablishedIDependableinternet_connectivity_establishedIDependableinternetConnectivityEstablishedIDependableInternetConnectivityEstablishedIDependableInternetConnectivityEstablishedIDependable required #
Dependency representing internet connectivity for these subnets.
isPendingLookupoptionalbooleanis_pending_lookupoptionalboolisPendingLookupoptionalBooleanIsPendingLookupoptionalboolIsPendingLookupoptional*bool = 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.

subnetIdsstring[]subnet_idstyping.List[str]subnetIdsList<String>SubnetIdsstring[]SubnetIds*[]*string required #
The subnet IDs.
subnetsISubnet[]subnetstyping.List[ISubnet]subnetsList<ISubnet>SubnetsISubnet[]Subnets*[]ISubnet required #
Selected subnet objects.