Skip to content

Instantly share code, notes, and snippets.

@JoshM1994
Created March 20, 2022 02:40
Show Gist options
  • Save JoshM1994/f7b0b64676eb346a9975cbba6e529bdb to your computer and use it in GitHub Desktop.
Save JoshM1994/f7b0b64676eb346a9975cbba6e529bdb to your computer and use it in GitHub Desktop.
const cfDist = new cloudfront.CloudFrontWebDistribution(this, 'CfDistribution', {
comment: 'CDK Cloudfront Secure S3',
viewerCertificate: ViewerCertificate.fromAcmCertificate(cert, {
aliases: [DOMAIN_NAME, WWW_DOMAIN_NAME],
}),
defaultRootObject: ROOT_INDEX_FILE,
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
httpVersion: HttpVersion.HTTP2,
priceClass: PriceClass.PRICE_CLASS_100, // the cheapest
originConfigs: [
{
s3OriginSource: {
originAccessIdentity: accessIdentity,
s3BucketSource: siteBucket,
originPath: `/${PROD_FOLDER}`,
},
behaviors: [
{
compress: true,
isDefaultBehavior: true,
},
],
},
],
// Allows React to handle all errors internally
errorConfigurations: [
{
errorCachingMinTtl: 300, // in seconds
errorCode: 403,
responseCode: 200,
responsePagePath: `/${ROOT_INDEX_FILE}`,
},
{
errorCachingMinTtl: 300, // in seconds
errorCode: 404,
responseCode: 200,
responsePagePath: `/${ROOT_INDEX_FILE}`,
},
],
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment