Reputation: 2085
I'm associating vpc to my lambda like this:
self.vpc = _ec2.Vpc.from_vpc_attributes(self, 'vpc', vpc_id=self.vpc_id,
availability_zones=['eu-west-1a', 'eu-west-1b', 'eu-west-1c'],
private_subnet_ids=[self.private_subnet_1, self.private_subnet_2,
self.private_subnet_3])
Now when I tried to associate this vpc with my lambda it shows a warning:
No routeTableId was provided to the subnet at 'PrivateSubnet1'. Attempting to read its .routeTable.routeTableId will return null/undefined.
routetableid
is optional as per documentation. So how can I get rid of this warning message?
Is there any methods can I use to find the lists of routtableid based on vpc and private subnets?
Upvotes: 7
Views: 7012
Reputation: 69
This is annoying me as well.
In the vpc module in CDK there is a piece of code which checks whether the Subnet object has a routeTableId and if not, adds the warning message to the Annotation object of the Subnet Object.
I just raised an upstream issue on github, let's see what the folks there say.
My suggestion is basically to get rid of the whole warning as it's only about a potential situation, in which case I would just have synth fail if it really occurs instead of warning everybody that it might potentially happen.
Upvotes: 6
Reputation: 110
Are you defining the subnets in this stack itself or importing them ? There is a routeTable attribute available on the subnet.
Having said that, are you getting the error during synth or deploy ? I have something similar on my end and was able to deploy the lambda in the vpc with just the below code.
_vpc = _ec2.Vpc.from_vpc_attributes(
self,
"VPC",
vpc_id = "vpc-13213",
availability_zones = ['us-east-1a'],
private_subnet_ids = ["subnet-123213"],
)
_lambda.Function(self, "lambda", handler="", ....... vpc=_vpc )
Upvotes: 0