@@ -47,7 +47,9 @@ interface IConfigProps {
47
47
48
48
49
49
export class HostingInfrastructure extends Construct {
50
+
50
51
public readonly hostingBucket : IBucket ;
52
+ public readonly distribution : cloudfront . Distribution ;
51
53
52
54
53
55
@@ -77,7 +79,7 @@ export class HostingInfrastructure extends Construct {
77
79
},
78
80
]);
79
81
*/
80
- const hostingBucket = new s3 . Bucket ( this , "HostingBucket" , {
82
+ this . hostingBucket = new s3 . Bucket ( this , "HostingBucket" , {
81
83
versioned : false ,
82
84
...( s3Logs ? { serverAccessLogsBucket : s3Logs } : { } ) ,
83
85
enforceSSL : true ,
@@ -90,9 +92,8 @@ export class HostingInfrastructure extends Construct {
90
92
} ) ,
91
93
} ) ;
92
94
93
- this . hostingBucket = hostingBucket ;
94
95
95
- const s3origin = new origins . S3Origin ( hostingBucket ) ;
96
+ const s3origin = new origins . S3Origin ( this . hostingBucket ) ;
96
97
97
98
const myResponseHeadersPolicy = new cloudfront . ResponseHeadersPolicy (
98
99
this ,
@@ -246,7 +247,7 @@ export class HostingInfrastructure extends Construct {
246
247
247
248
248
249
249
- const distribution = new cloudfront . Distribution ( this , "Distribution" , {
250
+ this . distribution = new cloudfront . Distribution ( this , "Distribution" , {
250
251
comment : "Static hosting - " + Aws . STACK_NAME ,
251
252
defaultRootObject : "index.html" ,
252
253
httpVersion : cloudfront . HttpVersion . HTTP2_AND_3 ,
@@ -279,7 +280,7 @@ export class HostingInfrastructure extends Construct {
279
280
: { } ) ,
280
281
} ) ;
281
282
282
- NagSuppressions . addResourceSuppressions ( distribution , [
283
+ NagSuppressions . addResourceSuppressions ( this . distribution , [
283
284
{
284
285
id : "AwsSolutions-CFR4" ,
285
286
reason :
@@ -290,7 +291,7 @@ export class HostingInfrastructure extends Construct {
290
291
//OAC is not implemented in CDK so tweaking is required:eplace OAI par OAC
291
292
//https://github.com/aws/aws-cdk/issues/21771
292
293
293
- const cfnDistribution = distribution . node . defaultChild as CfnDistribution ;
294
+ const cfnDistribution = this . distribution . node . defaultChild as CfnDistribution ;
294
295
cfnDistribution . addOverride (
295
296
"Properties.DistributionConfig.Origins.0.S3OriginConfig.OriginAccessIdentity" ,
296
297
""
@@ -300,7 +301,7 @@ export class HostingInfrastructure extends Construct {
300
301
oac . getAtt ( "Id" )
301
302
) ;
302
303
303
- const comS3PolicyOverride = hostingBucket . node . findChild ( "Policy" ) . node
304
+ const comS3PolicyOverride = this . hostingBucket . node . findChild ( "Policy" ) . node
304
305
. defaultChild as CfnBucketPolicy ;
305
306
const statement = comS3PolicyOverride . policyDocument . statements [ 1 ] ;
306
307
if ( statement [ "_principal" ] && statement [ "_principal" ] . CanonicalUser ) {
@@ -318,30 +319,30 @@ export class HostingInfrastructure extends Construct {
318
319
service : "cloudfront" ,
319
320
region : "" ,
320
321
resource : "distribution" ,
321
- resourceName : distribution . distributionId ,
322
+ resourceName : this . distribution . distributionId ,
322
323
arnFormat : ArnFormat . SLASH_RESOURCE_NAME ,
323
324
} ) ,
324
325
} ,
325
326
}
326
327
) ;
327
328
328
- const s3OriginNode = distribution . node
329
+ const s3OriginNode = this . distribution . node
329
330
. findAll ( )
330
331
//.filter((child) => child.node.id === "S3Origin");
331
332
. filter ( ( child ) => child . node . id === "S3Origin" ) ;
332
333
s3OriginNode [ 0 ] . node . tryRemoveChild ( "Resource" ) ;
333
334
//End of tweaking for OAC is not implemented in CDK so tweaking is required
334
335
335
336
new CfnOutput ( this , "DomainName" , {
336
- value : "https://" + distribution . domainName ,
337
+ value : "https://" + this . distribution . domainName ,
337
338
} ) ;
338
339
339
340
const stackName = calculateMainStackName ( params . hostingConfiguration ) ;
340
341
341
342
342
343
new ssm . StringParameter ( this , 'SSMConnectionRegion' , {
343
344
parameterName : '/' + stackName + '/' + SSM_DOMAIN_STR ,
344
- stringValue : distribution . domainName ,
345
+ stringValue : this . distribution . domainName ,
345
346
} ) ;
346
347
347
348
0 commit comments