I've created a fresh new VPC for a project with 2 route tables. 1 for public subnets and 1 for private subnets.
It all seems to work well, but I did notice that there is a standard route table without any subnets associated to it.

I think this is created upon creation of the VPC, but I'm not sure. I'm not able to find it anywhere in the VPC object when I print it out with console.log with cdk synth.
I also tried to cerate my VPC with CfnVPC, but the result stays the same.
This is my code:
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_ec2 } from 'aws-cdk-lib';
export class CcwVpcStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Create VPC called CCW with CIDR block 10.1.0.0/16 in us-east-1 with all availability zones in this region.
const vpc = new aws_ec2.Vpc(this, 'CCW', {
ipAddresses: aws_ec2.IpAddresses.cidr('10.1.0.0/16'),
availabilityZones: ['us-east-1a', 'us-east-1b', 'us-east-1c', 'us-east-1d', 'us-east-1e', 'us-east-1f'],
subnetConfiguration: [],
createInternetGateway: false,
});
const defaultRouteTable = vpc;
console.log(defaultRouteTable);
// Create Public Route Table
const publicRouteTable = new aws_ec2.CfnRouteTable(this, 'PublicRouteTable', {
vpcId: vpc.vpcId,
tags: [{ key: 'Name', value: 'PublicRouteTable' }]
});
// Create Private Route Table
const privateRouteTable = new aws_ec2.CfnRouteTable(this, 'PrivateRouteTable', {
vpcId: vpc.vpcId,
tags: [{ key: 'Name', value: 'PrivateRouteTable' }]
});
// Create Internet Gateway for Public Subnet Routing
const internetGateway = new aws_ec2.CfnInternetGateway(this, 'InternetGateway', {
tags: [{ key: 'Name', value: 'CCW-IGW' }]
});
new aws_ec2.CfnVPCGatewayAttachment(this, 'VpcGatewayAttachment', {
vpcId: vpc.vpcId,
internetGatewayId: internetGateway.ref
});
// Create a default route in the public route table to the Internet Gateway
new aws_ec2.CfnRoute(this, 'PublicRoute', {
routeTableId: publicRouteTable.ref,
destinationCidrBlock: '0.0.0.0/0',
gatewayId: internetGateway.ref
});
// Create 1 public subnet in this VPC with CIDR block 10.1.0.0/24
const publicServicesSubnet = new aws_ec2.CfnSubnet(this, 'PublicServicesSubnet', {
vpcId: vpc.vpcId,
cidrBlock: '10.1.0.0/24',
availabilityZone: 'us-east-1a',
tags: [{ key: 'Name', value: 'PublicServicesSubnet' }]
});
// Create 3 public subnets in this VPC with CIDR blocks 10.1.1.0/24, 10.1.2.0/24, 10.1.3.0/24
const publicSubnet1a = new aws_ec2.CfnSubnet(this, 'PublicSubnet1a', {
vpcId: vpc.vpcId,
cidrBlock: '10.1.1.0/24',
availabilityZone: 'us-east-1a',
tags: [{ key: 'Name', value: 'PublicSubnet1a' }]
});
const publicSubnet1b = new aws_ec2.CfnSubnet(this, 'PublicSubnet1b', {
vpcId: vpc.vpcId,
cidrBlock: '10.1.2.0/24',
availabilityZone: 'us-east-1b',
tags: [{ key: 'Name', value: 'PublicSubnet1b' }]
});
const publicSubnet1c = new aws_ec2.CfnSubnet(this, 'PublicSubnet1c', {
vpcId: vpc.vpcId,
cidrBlock: '10.1.3.0/24',
availabilityZone: 'us-east-1c',
tags: [{ key: 'Name', value: 'PublicSubnet1c' }]
});
// Create 3 private subnets in this VPC with CIDR blocks 10.1.11.0/24, 10.1.12.0/24, 10.1.13.0/24
const privateSubnet1a = new aws_ec2.CfnSubnet(this, 'PrivateSubnet1a', {
vpcId: vpc.vpcId,
cidrBlock: '10.1.11.0/24',
availabilityZone: 'us-east-1a',
tags: [{ key: 'Name', value: 'PrivateDbSubnet1a' }]
});
const privateSubnet1b = new aws_ec2.CfnSubnet(this, 'PrivateSubnet1b', {
vpcId: vpc.vpcId,
cidrBlock: '10.1.12.0/24',
availabilityZone: 'us-east-1b',
tags: [{ key: 'Name', value: 'PrivateSubnet1b' }]
});
const privateSubnet1c = new aws_ec2.CfnSubnet(this, 'PrivateSubnet1c', {
vpcId: vpc.vpcId,
cidrBlock: '10.1.13.0/24',
availabilityZone: 'us-east-1c',
tags: [{ key: 'Name', value: 'PrivateSubnet1c' }]
});
// Create 3 private subnets in this VPC with CIDR blocks 10.1.11.0/24, 10.1.12.0/24, 10.1.13.0/24
const privateDbSubnet1a = new aws_ec2.CfnSubnet(this, 'PrivateDbSubnet1a', {
vpcId: vpc.vpcId,
cidrBlock: '10.1.21.0/24',
availabilityZone: 'us-east-1a',
tags: [{ key: 'Name', value: 'PrivateDbSubnet1a' }]
});
const privateDbSubnet1b = new aws_ec2.CfnSubnet(this, 'PrivateDbSubnet1b', {
vpcId: vpc.vpcId,
cidrBlock: '10.1.22.0/24',
availabilityZone: 'us-east-1b',
tags: [{ key: 'Name', value: 'PrivateDbSubnet1b' }]
});
const privateDbSubnet1c = new aws_ec2.CfnSubnet(this, 'PrivateDbSubnet1c', {
vpcId: vpc.vpcId,
cidrBlock: '10.1.23.0/24',
availabilityZone: 'us-east-1c',
tags: [{ key: 'Name', value: 'PrivateDbSubnet1c' }]
});
// Associate Public Subnets with Public Route Table
new aws_ec2.CfnSubnetRouteTableAssociation(this, 'PublicServicesSubnetAssociation', {
subnetId: publicServicesSubnet.attrSubnetId,
routeTableId: publicRouteTable.ref
});
new aws_ec2.CfnSubnetRouteTableAssociation(this, 'PublicSubnet1aAssociation', {
subnetId: publicSubnet1a.attrSubnetId,
routeTableId: publicRouteTable.ref
});
new aws_ec2.CfnSubnetRouteTableAssociation(this, 'PublicSubnet1bAssociation', {
subnetId: publicSubnet1b.attrSubnetId,
routeTableId: publicRouteTable.ref
});
new aws_ec2.CfnSubnetRouteTableAssociation(this, 'PublicSubnet1cAssociation', {
subnetId: publicSubnet1c.attrSubnetId,
routeTableId: publicRouteTable.ref
});
// Associate Private Subnets with Private Route Table
new aws_ec2.CfnSubnetRouteTableAssociation(this, 'PrivateSubnet1AAssociation', {
subnetId: privateSubnet1a.attrSubnetId,
routeTableId: privateRouteTable.ref
});
new aws_ec2.CfnSubnetRouteTableAssociation(this, 'PrivateSubnet1BAssociation', {
subnetId: privateSubnet1b.attrSubnetId,
routeTableId: privateRouteTable.ref
});
new aws_ec2.CfnSubnetRouteTableAssociation(this, 'PrivateSubnet1CAssociation', {
subnetId: privateSubnet1c.attrSubnetId,
routeTableId: privateRouteTable.ref
});
new aws_ec2.CfnSubnetRouteTableAssociation(this, 'PrivateDbSubnet1AAssociation', {
subnetId: privateDbSubnet1a.attrSubnetId,
routeTableId: privateRouteTable.ref
});
new aws_ec2.CfnSubnetRouteTableAssociation(this, 'PrivateDbSubnet1BAssociation', {
subnetId: privateDbSubnet1b.attrSubnetId,
routeTableId: privateRouteTable.ref
});
new aws_ec2.CfnSubnetRouteTableAssociation(this, 'PrivateDbSubnet1CAssociation', {
subnetId: privateDbSubnet1c.attrSubnetId,
routeTableId: privateRouteTable.ref
});
}
}
I'm not sure how I can access this Route Table, so I can maybe use this as my public router.