Skip to content

Commit 37c5c68

Browse files
committed
start of v2 migration
1 parent 436ffc1 commit 37c5c68

File tree

4 files changed

+1472
-3609
lines changed

4 files changed

+1472
-3609
lines changed

lib/spa-deploy/spa-deploy-construct.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import {
55
Behavior,
66
SSLMethod,
77
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';
1718

1819
export interface SPADeployConfig {
1920
readonly indexDoc:string,
@@ -55,10 +56,10 @@ export interface SPADeploymentWithCloudFront extends SPADeployment {
5556
readonly distribution: CloudFrontWebDistribution,
5657
}
5758

58-
export class SPADeploy extends cdk.Construct {
59+
export class SPADeploy extends Construct {
5960
globalConfig: SPAGlobalConfig;
6061

61-
constructor(scope: cdk.Construct, id:string, config?:SPAGlobalConfig) {
62+
constructor(scope: Construct, id:string, config?:SPAGlobalConfig) {
6263
super(scope, id);
6364

6465
if (typeof config !== 'undefined') {
@@ -85,7 +86,7 @@ export class SPADeploy extends cdk.Construct {
8586
bucketConfig.encryption = s3.BucketEncryption.S3_MANAGED;
8687
}
8788

88-
if (this.globalConfig.ipFilter === true || isForCloudFront === true) {
89+
if (this.globalConfig.ipFilter === true || isForCloudFront === true || typeof config.blockPublicAccess !== 'undefined') {
8990
bucketConfig.publicReadAccess = false;
9091
if (typeof config.blockPublicAccess !== 'undefined') {
9192
bucketConfig.blockPublicAccess = config.blockPublicAccess;
@@ -96,7 +97,7 @@ export class SPADeploy extends cdk.Construct {
9697

9798
if (this.globalConfig.ipFilter === true && isForCloudFront === false) {
9899
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');
100101
}
101102

102103
const bucketPolicy = new PolicyStatement();
@@ -206,12 +207,12 @@ export class SPADeploy extends cdk.Construct {
206207

207208
if (config.exportWebsiteUrlOutput === true) {
208209
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');
210211
}
211212
cfnOutputConfig.exportName = config.exportWebsiteUrlName;
212213
}
213214

214-
new cdk.CfnOutput(this, 'URL', cfnOutputConfig);
215+
new CfnOutput(this, 'URL', cfnOutputConfig);
215216

216217
return { websiteBucket };
217218
}
@@ -234,7 +235,7 @@ export class SPADeploy extends cdk.Construct {
234235
role: config.role,
235236
});
236237

237-
new cdk.CfnOutput(this, 'cloudfront domain', {
238+
new CfnOutput(this, 'cloudfront domain', {
238239
description: 'The domain of the website',
239240
value: distribution.distributionDomainName,
240241
});

0 commit comments

Comments
 (0)