@@ -55,7 +55,7 @@ export class SandboxStack extends Construct {
5555 } ,
5656 } ) ;
5757
58- // Public Subnets (for App Runner VPC connector and NAT )
58+ // Public Subnets (for App Runner VPC connector and RDS )
5959 const publicSubnet1 = new Subnet ( this , `${ id } -public-subnet-1` , {
6060 vpcId : vpc . id ,
6161 cidrBlock : '10.0.1.0/24' ,
@@ -78,29 +78,6 @@ export class SandboxStack extends Construct {
7878 } ,
7979 } ) ;
8080
81- // Private Subnets (for App Runner VPC connector with NAT Gateway access)
82- const privateSubnet1 = new Subnet ( this , `${ id } -private-subnet-1` , {
83- vpcId : vpc . id ,
84- cidrBlock : '10.0.11.0/24' ,
85- availabilityZone : Fn . element ( azs . names , 0 ) ,
86- mapPublicIpOnLaunch : false ,
87- tags : {
88- Name : `${ id } -private-subnet-1` ,
89- Environment : environment ,
90- } ,
91- } ) ;
92-
93- const privateSubnet2 = new Subnet ( this , `${ id } -private-subnet-2` , {
94- vpcId : vpc . id ,
95- cidrBlock : '10.0.12.0/24' ,
96- availabilityZone : Fn . element ( azs . names , 1 ) ,
97- mapPublicIpOnLaunch : false ,
98- tags : {
99- Name : `${ id } -private-subnet-2` ,
100- Environment : environment ,
101- } ,
102- } ) ;
103-
10481 // Route table for public subnets
10582 const publicRouteTable = new RouteTable ( this , `${ id } -public-rt` , {
10683 vpcId : vpc . id ,
@@ -126,79 +103,69 @@ export class SandboxStack extends Construct {
126103 routeTableId : publicRouteTable . id ,
127104 } ) ;
128105
129- // Elastic IPs for NAT Gateways
130- const eip1 = new Eip ( this , `${ id } -eip-1` , {
131- domain : 'vpc' ,
106+ // Private subnets for App Runner VPC connector
107+ const privateSubnet1 = new Subnet ( this , `${ id } -private-subnet-1` , {
108+ vpcId : vpc . id ,
109+ cidrBlock : '10.0.11.0/24' ,
110+ availabilityZone : Fn . element ( azs . names , 0 ) ,
132111 tags : {
133- Name : `${ id } -eip -1` ,
112+ Name : `${ id } -private-subnet -1` ,
134113 Environment : environment ,
135114 } ,
136115 } ) ;
137116
138- const eip2 = new Eip ( this , `${ id } -eip-2` , {
139- domain : 'vpc' ,
117+ const privateSubnet2 = new Subnet ( this , `${ id } -private-subnet-2` , {
118+ vpcId : vpc . id ,
119+ cidrBlock : '10.0.12.0/24' ,
120+ availabilityZone : Fn . element ( azs . names , 1 ) ,
140121 tags : {
141- Name : `${ id } -eip -2` ,
122+ Name : `${ id } -private-subnet -2` ,
142123 Environment : environment ,
143124 } ,
144125 } ) ;
145126
146- // NAT Gateways in public subnets
147- const natGateway1 = new NatGateway ( this , `${ id } -nat-1` , {
148- allocationId : eip1 . id ,
149- subnetId : publicSubnet1 . id ,
127+ // Elastic IP for NAT Gateway
128+ const natEip = new Eip ( this , `${ id } -nat-eip` , {
129+ domain : 'vpc' ,
150130 tags : {
151- Name : `${ id } -nat-1 ` ,
131+ Name : `${ id } -nat-eip ` ,
152132 Environment : environment ,
153133 } ,
154134 } ) ;
155135
156- const natGateway2 = new NatGateway ( this , `${ id } -nat-2` , {
157- allocationId : eip2 . id ,
158- subnetId : publicSubnet2 . id ,
136+ // NAT Gateway in public subnet
137+ const natGateway = new NatGateway ( this , `${ id } -nat-gw` , {
138+ allocationId : natEip . id ,
139+ subnetId : publicSubnet1 . id ,
159140 tags : {
160- Name : `${ id } -nat-2 ` ,
141+ Name : `${ id } -nat-gw ` ,
161142 Environment : environment ,
162143 } ,
163144 } ) ;
164145
165- // Route tables for private subnets
166- const privateRouteTable1 = new RouteTable ( this , `${ id } -private-rt-1 ` , {
146+ // Route table for private subnets
147+ const privateRouteTable = new RouteTable ( this , `${ id } -private-rt` , {
167148 vpcId : vpc . id ,
168149 tags : {
169- Name : `${ id } -private-rt-1 ` ,
150+ Name : `${ id } -private-rt` ,
170151 Environment : environment ,
171152 } ,
172153 } ) ;
173154
174- new Route ( this , `${ id } -private-route-1 ` , {
175- routeTableId : privateRouteTable1 . id ,
155+ new Route ( this , `${ id } -private-route` , {
156+ routeTableId : privateRouteTable . id ,
176157 destinationCidrBlock : '0.0.0.0/0' ,
177- natGatewayId : natGateway1 . id ,
158+ natGatewayId : natGateway . id ,
178159 } ) ;
179160
180161 new RouteTableAssociation ( this , `${ id } -private-rta-1` , {
181162 subnetId : privateSubnet1 . id ,
182- routeTableId : privateRouteTable1 . id ,
183- } ) ;
184-
185- const privateRouteTable2 = new RouteTable ( this , `${ id } -private-rt-2` , {
186- vpcId : vpc . id ,
187- tags : {
188- Name : `${ id } -private-rt-2` ,
189- Environment : environment ,
190- } ,
191- } ) ;
192-
193- new Route ( this , `${ id } -private-route-2` , {
194- routeTableId : privateRouteTable2 . id ,
195- destinationCidrBlock : '0.0.0.0/0' ,
196- natGatewayId : natGateway2 . id ,
163+ routeTableId : privateRouteTable . id ,
197164 } ) ;
198165
199166 new RouteTableAssociation ( this , `${ id } -private-rta-2` , {
200167 subnetId : privateSubnet2 . id ,
201- routeTableId : privateRouteTable2 . id ,
168+ routeTableId : privateRouteTable . id ,
202169 } ) ;
203170
204171 // Security Groups
@@ -383,21 +350,17 @@ export class SandboxStack extends Construct {
383350 ) ;
384351
385352 // App Runner VPC Connector
386- // Note: abbreviated name with 'v2' suffix to allow clean migration from public to private subnets
387353 const vpcConnector = new ApprunnerVpcConnector (
388354 this ,
389355 `${ id } -vpc-connector` ,
390356 {
391- vpcConnectorName : `${ id } -vpc-conn-v2 ` ,
357+ vpcConnectorName : `${ id } -vpc-connector ` ,
392358 subnets : [ privateSubnet1 . id , privateSubnet2 . id ] ,
393359 securityGroups : [ appRunnerSecurityGroup . id ] ,
394360 tags : {
395361 Name : `${ id } -vpc-connector` ,
396362 Environment : environment ,
397363 } ,
398- lifecycle : {
399- createBeforeDestroy : true ,
400- } ,
401364 }
402365 ) ;
403366
0 commit comments