(ec2): Fails to create subnet with `fromSubnetAttributes` without `routeTableId`
See original GitHub issueDescribe 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:
- Created a year ago
- Reactions:7
- Comments:7 (4 by maintainers)
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:
It would be great to have the warning (or an exception) only when
routeTableId
is read.Using dotnet , having same issue:
If we are given warning we should have ability to add a route table id to theFromSubnetId these subnets use…