Is it possible to add route entries to a route table via cdk?
The way I tried is: using a vpc construct I tried to iterate over the public_subnets + private_subnets attributes lists to get the routeTables. But these return IRouteTable -- with which I can't seem to do any updates. Anyone know how to do it? Thanks.
You can able to solve this by instantiating new CloudFormation Route resources:
vpc.privateSubnets.forEach(({ routeTable: { routeTableId } }, index) => {
new CfnRoute(stack, 'PrivateSubnetPeeringConnectionRoute' + index, {
destinationCidrBlock: '10.0.0.0/16',
routeTableId,
vpcPeeringConnectionId: peeringConnection.ref,
})
})
You will need to know the ID of the peering connection for those routes. In the example above, it's referenced as it's created in the same stack:
const peeringConnection = new CfnVPCPeeringConnection(
stack,
'PeeringConnection',
{
peerVpcId: peerVpc.vpcId,
vpcId: vpc.vpcId,
}
)
Consider [1] , [2] and [3] for more details
[2] https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.Subnet.html#add-wbr-routeid-options