(vpc.selectSubnets): Cannot find a subnet by subnetGroupName in a lookup VPC
See original GitHub issueUnable to get subnets by their group name in a lookup VPC
Reproduction Steps
I have created a vpc in my infrastructure repo and is referenced in another repo. When I try to get subnets with group name rds-private-subnet
, I get following error.
Error: There are no subnet groups with name 'rds-private-subnet' in this VPC. Available names: public-subnet,private-subnet
at LookedUpVpc.selectSubnetObjectsByName (/Users/user/projects/auth/node_modules/@aws-cdk/aws-ec2/lib/vpc.ts:343:13)
Below is the code snippet that caused it.
// @ infrastructure/stack.ts
const privateSubnectConfiguration = {
cidrMask: 24,
name: "private-subnet",
subnetType: ec2.SubnetType.PRIVATE,
};
const publicSubnectConfiguration = {
cidrMask: 24,
name: "public-subnet",
subnetType: ec2.SubnetType.PUBLIC,
};
const rdsPrivateSubnetConfiguration = {
cidrMask: 24,
name: "rds-private-subnet",
subnetType: ec2.SubnetType.PRIVATE,
};
const vpc = new ec2.Vpc(this, "test-vpc", {
cidr: "10.0.0.0/16",
subnetConfiguration: [
publicSubnectConfiguration,
privateSubnectConfiguration,
rdsPrivateSubnetConfiguration,
],
maxAzs: 2,
natGateways: 1,
natGatewayProvider,
});
// @ auth/stack.ts
const vpc = ec2.Vpc.fromLookup(this, "vpc", {
vpcId: <vpc-id>
});
const rdsSubnetGroup = new rds.SubnetGroup(this, "RDS subnet group", {
description: "RDS subnet group",
vpc: vpc,
vpcSubnets: vpc.selectSubnets({
subnetGroupName: "rds-private-subnet",
}),
});
What did you expect to happen?
I expected to get the subnets with group name rds-private-subnet
.
What actually happened?
cdk
threw an error saying the subnets with group name rds-private-subnet
does not exist.
Error: There are no subnet groups with name 'rds-private-subnet' in this VPC. Available names: public-subnet,private-subnet
at LookedUpVpc.selectSubnetObjectsByName (/Users/user/projects/auth/node_modules/@aws-cdk/aws-ec2/lib/vpc.ts:343:13)
Environment
- **CDK CLI Version :1.112.0
- Framework Version:
- **Node.js Version:15.3.0
- **OS :macos
- **Language (Version):~3.9.7
Other
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Cannot refer to subnet by name for imported VPC · Issue #3650
JSIIError: There are no subnets named 'xxxx' in this VPC. Use a different VPC subnet selection. Example code piece: vpc = aws_ec2.Vpc.
Read more >interface SubnetSelection · AWS CDK
This field does not select individual subnets, it selects all subnets that share the given subnet group name. This is the name supplied...
Read more >Subnet Selection Example in AWS CDK | bobbyhadz
By using the subnetGroupName property, we are able to select a specific subnet group by name, in case we have provisioned a VPC...
Read more >AWS CDK subnet selections - Stack Overflow
I tried to create LB in CDK as below. lb = elbv2.ApplicationLoadBalancer( self, "LB", load_balancer_name="Load Balancer CDK", vpc = vpc, ...
Read more >Import Existing VPCs and Subnets into a CDK Python Project
The AWS CDK makes it really easy to create a VPC and subnets and to use ... When you create a Subnet using...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey @ludbek,
I was able to reproduce this error if I:
public-subnet
andprivate-subnet
in yourcdk.context.json
cdk.context.json
already has the data cached for your VPC from when we first looked up the VPC, so it will use this cached data instead of actually getting data.To fix this, you can simply delete your
cdk.context.json
(this will update it the next time you run the stack) or you can manage your cached data⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.