'AWS CDK - Getting InvalidRouteTableId.Malformed when creating Route Table
I am getting the below exception when trying to create a Route Table through AWS CDK library. I went through the naming standards and am making sure to follow it. From the exception message, it seems to be removing the "-" from the id I provided. Please let me know what could be the issue
CDK statement for creating the Route Table. I am passing the vpc id as required:
aws_cdk.aws_ec2.CfnRouteTable(self,id="rtb-0ad2be93946c6be65",vpc_id=vpc.vpc_id)
Exception:
Invalid id: "rtb0ad2be93946c6be65" (Service: AmazonEC2; Status Code: 400; Error Code: InvalidRouteTableId.Malformed; Request ID: 342b6743-b0e3-4ceb-b86d-3ae9564f7923; Pr oxy: null)
Solution 1:[1]
The issue turned out nothing to do with the way I was creating the route table. But rather what I was doing to create the Route later for that route table. I had to pass the route table using ".ref" rather than ".logical_id"
I am using the below code for creating the table and route now and its working fine:
route_table = aws_cdk.aws_ec2.CfnRouteTable(self,id="rtb-0ad2be93946c6be65",vpc_id=vpc.vpc_id)
target_route = aws_ec2.CfnRoute(self,id="someroutename",route_table_id=route_table.ref,gateway_id=vpn_gateway.ref,destination_cidr_block="10.0.0.0/22")
But, I do think CDK can do better with error handling
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DigVen |