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.

(ec2): Fails to create subnet with `fromSubnetAttributes` without `routeTableId`

See original GitHub issue

Describe the bug

When I create a Subnet using ec2.Subnet.from_subnet_attributes and don’t specify a routeTableId, I’m getting the following warning:

[Warning at /euc1-dv-rest-alb-alb/subnet-0] No routeTableId was provided to the subnet at 'euc1-dv-rest-alb-alb/subnet-0'. Attempting to read its .routeTable.routeTableId will return null/undefined. (More info: https://github.com/aws/aws-cdk/pull/3171)

While this warning definitely serves it’s purpose, I’m missing the option to turn it off or acknowledge it when for example I anyway don’t have the intention to read the routeTableId of the subnet.

It is just spamming the console when running synth but also prevents me from using --strict.

Expected Behavior

This warning shouldn’t be there. at all.

Current Behavior

cdk synth produces said warning, regardless of whether you’re actually trying to read the routeTableId parameter or not.

Reproduction Steps

Just do this in one of your stacks.

ec2.Subnet.from_subnet_attributes(self, id="subnet", subnet_id='subnet-0123456789abcdef0')

Possible Solution

Either the routeTableId Parameter should be mandatory for ec2.Subnet.from_subnet_attributes or if it stays optional (which is probably the better solution) it should not automatically trigger a warning. Instead synth should fail if you omit the routeTableId parameter and try to read it later. Maybe an error message with similar content could be created if this happens.

Additional Information/Context

The line of code where this happens is https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-ec2/lib/vpc.ts#L2103.

CDK CLI Version

2.19.0 (build e0d3e62)

Framework Version

No response

Node.js Version

v14.19.0

OS

Ubuntu 20.04.3 LTS, Linux VIE-NOMPOS-MOB 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Language

Typescript, Python, .NET, Java, Go

Language Version

not relevant

Other information

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:7
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jordan-broughcommented, Jun 14, 2022

This happens with ec2.Subnet.fromSubnetId as well, which doesn’t even have an option to specify a routeTableId.

My current terrible workaround to avoid warning spam:

const subnet = cdk.aws_ec2.Subnet.fromSubnetId(this, 'Subnet', 'subnet-XXX');
// hack to avoid warning spam
subnet.node._metadata = subnet.node._metadata.filter((item) =>
  item.type !== 'aws:cdk:warning' || !/No routeTableId was provided to the subnet/.test(item.data)
);

It would be great to have the warning (or an exception) only when routeTableId is read.

0reactions
petejewelscommented, Aug 25, 2022

Using dotnet , having same issue:

TaskSubnets = new SubnetSelection
                    {
                        Subnets = new[] {
                           Subnet.FromSubnetId(this, "subnet1", "subnet-64564"),
                            Subnet.FromSubnetId(this, "subnet2", "subnet-987987")
                        },
                        
                    },

If we are given warning we should have ability to add a route table id to theFromSubnetId these subnets use…

Read more comments on GitHub >

github_iconTop Results From Across the Web

class Subnet (construct) · AWS CDK
Create a default route that points to a passed IGW, with a dependency on the IGW's attachment to the VPC. addDefaultNatRoute(natGatewayId), Adds an...
Read more >
awslabs/aws-cdk - Gitter
Either the subnets listed with ec2.VpcNetworkProvider or imported with ec2.PrivateSubnet.fromSubnetAttributes have routeTableId: undefined.
Read more >
Creating a ROSA cluster with Private Link enabled - mobb.ninja
As an example, you cannot install ROSA to us-east-1e AZ, but us-east-1b works fine. Option 1 - VPC with a private subnet and...
Read more >
@rhaws/aws-ec2 - npm
A default VPC configuration will not include isolated subnets, ... No resources will // be created for this subnet, but the IP range...
Read more >
AWS CloudFormation: Reference to subnet causing error
I am trying to build an AWS CloudFormation template to create a VPC, public subnet, and then launch an EC2 instance into that...
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