diff --git a/cdk-stack.ts b/cdk-stack.ts new file mode 100644 index 00000000..752bcc62 --- /dev/null +++ b/cdk-stack.ts @@ -0,0 +1,16 @@ +const siteBucket = new s3.Bucket(this, 'SiteBucket', { + websiteIndexDocument: 'index.html', + blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, // Keep it private! +}); + +const distribution = new cloudfront.Distribution(this, 'SiteDistribution', { + defaultBehavior: { origin: new origins.S3Origin(siteBucket) }, + defaultRootObject: 'index.html', +}); + +new s3deploy.BucketDeployment(this, 'DeployWithInvalidation', { + sources: [s3deploy.Source.asset('../dist')], + destinationBucket: siteBucket, + distribution, // This automatically triggers the invalidation + distributionPaths: ['/*'], +}); diff --git a/package.json b/package.json index d5b84313..b2f69d5f 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,14 @@ "scripts": { "ng": "ng", "start": "ng serve", - "build": "ng build", + "build": "ng build --prefix frontend", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", "prepare": "husky", - "lint:format": "npx --no-install lint-staged && npx --no-install pretty-quick --staged" + "lint:format": "npx --no-install lint-staged && npx --no-install pretty-quick --staged", + "cdk:deploy": "npm run build && cd cdk && cdk deploy", + "cdk:destroy": "cd cdk && cdk destroy" }, "private": true, "dependencies": {