in source/5-unicornPics/backend/lib/frontend/frontend.ts [13:61]
constructor(scope: cdk.Construct, id: string) {
super(scope, id);
this.activateBucket = new s3.Bucket(this, 'activateBucket', {
versioned: true,
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
});
this.activateDistribution = new cloudfront.Distribution(
this,
'activateDistribution',
{
defaultBehavior: {
origin: new origins.S3Origin(this.activateBucket),
},
defaultRootObject: 'index.html',
errorResponses: [
{ httpStatus: 404, responsePagePath: '/index.html', responseHttpStatus: 200 },
{ httpStatus: 403, responsePagePath: '/index.html', responseHttpStatus: 200 },
],
}
);
this.activateBucket.addCorsRule({
allowedMethods: [
s3.HttpMethods.PUT
],
allowedHeaders: [
"*"
],
allowedOrigins: [
'*', // `https://${this.activateDistribution.distributionDomainName}`, => Circular dependency
]
});
this.siteDeployment = new s3deploy.BucketDeployment(this, 'DeployWithInvalidation', {
sources: [
s3deploy.Source.asset(path.resolve(__dirname, '../../../webapp/build')),
],
destinationBucket: this.activateBucket,
distribution: this.activateDistribution,
distributionPaths: ['/*'],
});
new cdk.CfnOutput(this, 'websiteUrl', {
value: `https://${this.activateDistribution.distributionDomainName}`
});
}