34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
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,
|
|
});
|
|
}
|
|
}
|