@@ -5,15 +5,16 @@ import {
5
5
Behavior ,
6
6
SSLMethod ,
7
7
SecurityPolicyProtocol ,
8
- } from '@aws-cdk/aws-cloudfront' ;
9
- import { PolicyStatement , Role , AnyPrincipal , Effect } from '@aws-cdk/aws-iam' ;
10
- import { HostedZone , ARecord , RecordTarget } from '@aws-cdk/aws-route53' ;
11
- import { DnsValidatedCertificate } from '@aws-cdk/aws-certificatemanager' ;
12
- import { HttpsRedirect } from '@aws-cdk/aws-route53-patterns' ;
13
- import { CloudFrontTarget } from '@aws-cdk/aws-route53-targets' ;
14
- import cdk = require( '@aws-cdk/core' ) ;
15
- import s3deploy = require( '@aws-cdk/aws-s3-deployment' ) ;
16
- import s3 = require( '@aws-cdk/aws-s3' ) ;
8
+ } from 'aws-cdk-lib/aws-cloudfront' ;
9
+ import { PolicyStatement , Role , AnyPrincipal , Effect } from 'aws-cdk-lib/aws-iam' ;
10
+ import { HostedZone , ARecord , RecordTarget } from 'aws-cdk-lib/aws-route53' ;
11
+ import { DnsValidatedCertificate } from 'aws-cdk-lib/aws-certificatemanager' ;
12
+ import { HttpsRedirect } from 'aws-cdk-lib/aws-route53-patterns' ;
13
+ import { CloudFrontTarget } from 'aws-cdk-lib/aws-route53-targets' ;
14
+ import { CfnOutput } from 'aws-cdk-lib' ;
15
+ import s3deploy = require( 'aws-cdk-lib/aws-s3-deployment' ) ;
16
+ import s3 = require( 'aws-cdk-lib/aws-s3' ) ;
17
+ import { Construct } from 'constructs' ;
17
18
18
19
export interface SPADeployConfig {
19
20
readonly indexDoc :string ,
@@ -55,10 +56,10 @@ export interface SPADeploymentWithCloudFront extends SPADeployment {
55
56
readonly distribution : CloudFrontWebDistribution ,
56
57
}
57
58
58
- export class SPADeploy extends cdk . Construct {
59
+ export class SPADeploy extends Construct {
59
60
globalConfig : SPAGlobalConfig ;
60
61
61
- constructor ( scope : cdk . Construct , id :string , config ?:SPAGlobalConfig ) {
62
+ constructor ( scope : Construct , id :string , config ?:SPAGlobalConfig ) {
62
63
super ( scope , id ) ;
63
64
64
65
if ( typeof config !== 'undefined' ) {
@@ -85,7 +86,7 @@ export class SPADeploy extends cdk.Construct {
85
86
bucketConfig . encryption = s3 . BucketEncryption . S3_MANAGED ;
86
87
}
87
88
88
- if ( this . globalConfig . ipFilter === true || isForCloudFront === true ) {
89
+ if ( this . globalConfig . ipFilter === true || isForCloudFront === true || typeof config . blockPublicAccess !== 'undefined' ) {
89
90
bucketConfig . publicReadAccess = false ;
90
91
if ( typeof config . blockPublicAccess !== 'undefined' ) {
91
92
bucketConfig . blockPublicAccess = config . blockPublicAccess ;
@@ -96,7 +97,7 @@ export class SPADeploy extends cdk.Construct {
96
97
97
98
if ( this . globalConfig . ipFilter === true && isForCloudFront === false ) {
98
99
if ( typeof this . globalConfig . ipList === 'undefined' ) {
99
- this . node . addError ( 'When IP Filter is true then the IP List is required' ) ;
100
+ throw new Error ( 'When IP Filter is true then the IP List is required' ) ;
100
101
}
101
102
102
103
const bucketPolicy = new PolicyStatement ( ) ;
@@ -206,12 +207,12 @@ export class SPADeploy extends cdk.Construct {
206
207
207
208
if ( config . exportWebsiteUrlOutput === true ) {
208
209
if ( typeof config . exportWebsiteUrlName === 'undefined' || config . exportWebsiteUrlName === '' ) {
209
- this . node . addError ( 'When Output URL as AWS Export property is true then the output name is required' ) ;
210
+ throw new Error ( 'When Output URL as AWS Export property is true then the output name is required' ) ;
210
211
}
211
212
cfnOutputConfig . exportName = config . exportWebsiteUrlName ;
212
213
}
213
214
214
- new cdk . CfnOutput ( this , 'URL' , cfnOutputConfig ) ;
215
+ new CfnOutput ( this , 'URL' , cfnOutputConfig ) ;
215
216
216
217
return { websiteBucket } ;
217
218
}
@@ -234,7 +235,7 @@ export class SPADeploy extends cdk.Construct {
234
235
role : config . role ,
235
236
} ) ;
236
237
237
- new cdk . CfnOutput ( this , 'cloudfront domain' , {
238
+ new CfnOutput ( this , 'cloudfront domain' , {
238
239
description : 'The domain of the website' ,
239
240
value : distribution . distributionDomainName ,
240
241
} ) ;
0 commit comments