feat: Add deployment script

This commit is contained in:
2024-01-30 17:33:47 +01:00
parent cd5de224fe
commit edfe447478
11 changed files with 4511 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import * as cdk from 'aws-cdk-lib';
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
import * as origins from 'aws-cdk-lib/aws-cloudfront-origins';
import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment';
import { Construct } from 'constructs';
import path = require('path');
export class DeploymentStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const staticBucket = new s3.Bucket(this, 'StaticBucket', {
autoDeleteObjects: true,
removalPolicy: cdk.RemovalPolicy.DESTROY,
});
const distribution = new cloudfront.Distribution(this, 'CDNServer', {
defaultBehavior: { origin: new origins.S3Origin(staticBucket) },
defaultRootObject: 'index.html'
});
new cdk.CfnOutput(this, 'URL', {
value: `https://${distribution.domainName}`
});
new s3deploy.BucketDeployment(this, 'DeployWithInvalidation', {
sources: [s3deploy.Source.asset(path.join(__dirname, '../../dist'))],
destinationBucket: staticBucket,
distribution: distribution,
});
}
}