@@ -14,7 +14,6 @@ export class StaticSiteStack extends cdk.Stack {
1414 constructor ( scope : cdk . Construct , id : string , props : StaticSiteStackProps ) {
1515 super ( scope , id , props ) ;
1616
17- const certArn = "arn:aws:acm:us-east-1:725714232753:certificate/63474aa5-080f-4601-bb09-72e0d5eb2d29" ;
1817 const zone = route53 . HostedZone . fromLookup ( this , 'Zone' , { domainName : props . domainName } ) ;
1918 const siteDomain = `${ props . siteSubDomain } .${ props . domainName } ` ;
2019 // The code that defines your stack goes here
@@ -30,11 +29,19 @@ export class StaticSiteStack extends cdk.Stack {
3029 removalPolicy : cdk . RemovalPolicy . DESTROY , // NOT recommended for production code
3130 } ) ;
3231
33-
32+ const certificateArn = new acm . DnsValidatedCertificate (
33+ this ,
34+ "SiteCertificate" ,
35+ {
36+ domainName : siteDomain ,
37+ hostedZone : zone ,
38+ region : "us-east-1" , // Cloudfront only checks this region for certificates.
39+ }
40+ ) . certificateArn
3441
3542 const distribution = new cloudfront . CloudFrontWebDistribution ( this , 'SiteDistribution' , {
3643 aliasConfiguration : {
37- acmCertRef : certArn ,
44+ acmCertRef : certificateArn ,
3845 names : [ siteDomain ] ,
3946 sslMethod : cloudfront . SSLMethod . SNI ,
4047 securityPolicy : cloudfront . SecurityPolicyProtocol . TLS_V1_1_2016 ,
@@ -53,7 +60,7 @@ export class StaticSiteStack extends cdk.Stack {
5360 } ) ;
5461 new route53 . ARecord ( this , 'SiteAliasRecord' , {
5562 recordName : siteDomain ,
56- target : route53 . AddressRecordTarget . fromAlias ( new targets . CloudFrontTarget ( distribution ) ) ,
63+ target : route53 . RecordTarget . fromAlias ( new targets . CloudFrontTarget ( distribution ) ) ,
5764 zone
5865 } ) ;
5966
0 commit comments