aws-cdk: (ec2): Fails to create subnet with `fromSubnetAttributes` without `routeTableId`
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
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 24
- Comments: 16 (9 by maintainers)
Better “workaround” with the recent addition of
addWarningsV2This 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
routeTableIdis read.Do you have a Python way to hack this?
Doesn’t seem like I can modify the metadata
Only adding the warning when
routeTableIdis read sounds good. Happy to accept a PR that changes this behavior.This issue was created from missing an option to acknowledge the warning. With the addition of addWarningsV2 @dontirun mentioned, this issue can probably be closed.
Lots of customers frequently get tripped up by their imported resources having undefined values, usually due to expecting CDK to look the values up itself.
This warning has been here for a long time, and we have other warnings similar to this - but usually only when the value would be read. Personally I’d be perfectly ok with removing this warning altogether, because we’re actively working on documentation which will reduce confusion surrounding imported resources. Once that new documentation is live we could remove this warning. In the meantime, we’d definitely still accept a PR which only throws this warning when the routeTableId is read
@DesAWSume Check out our Python examples of escape hatches