question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(vpc.selectSubnets): Cannot find a subnet by subnetGroupName in a lookup VPC

See original GitHub issue

Unable 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:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
peterwoodworthcommented, Aug 2, 2021

Hey @ludbek,

I was able to reproduce this error if I:

  • First lookup the VPC before configuring the RDS private subnet
    • this will cache public-subnet and private-subnet in your cdk.context.json
  • Then add the RDS subnet to the VPC and deploy
  • Add the RDS subnet group to the stack with the looked up VPC. Your 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

0reactions
github-actions[bot]commented, Aug 4, 2021

⚠️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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found