When importing a vpc that is created outside CDK code to cdk, it will build a cdk.context.json
file with vpc and subnet information and selectSubnets
is merely extracting information from that vpc object that is built in that context file. Some documentation here.
vpc = ec2.Vpc.fromLookup(this, 'myVpc',{isDefault: false, vpcId:vpcId });
Subnet type is determined by CDK on multiple criteria
- Presence of tag
aws-cdk:subnet-type
which will be there if vpc is created by CDK itself.
- Based on presence of Internet Gateway (IGW), Nat Gateway or No Gateway. Ex: If there route to IGW, then it will be treated as PUBLIC.
We can observe what type cdk derived in cdk.context file.

If we don't like the subnet type by default or We need to specific subnets, cases where we have too many private subnets and we need import specefic one, we can always import them like this:
const subnet1 = ec2.Subnet.fromSubnetId(this, 'private-subnet-1', 'subnet-1234345');
const subnet2 = ec2.Subnet.fromSubnetId(this, 'private-subnet-2', 'subnet-456789');