Skip to content

Instantly share code, notes, and snippets.

@jewelsjacobs
Created August 8, 2019 19:28
Show Gist options
  • Select an option

  • Save jewelsjacobs/4e5cff3de439951624e1899ac5ffcfff to your computer and use it in GitHub Desktop.

Select an option

Save jewelsjacobs/4e5cff3de439951624e1899ac5ffcfff to your computer and use it in GitHub Desktop.
Cloudfront Stack
import { App, Stack, StackProps, RemovalPolicy } from '@aws-cdk/core';
import { StaticWebsite } from '@cloudcomponents/cdk-static-website';
/**
* Static site infrastructure, which uses an S3 bucket for the content.
*
* The site redirects from HTTP to HTTPS, using a CloudFront distribution,
* Route53 alias record, and ACM certificate.
*
* The ACM certificate is expected to be created and validated outside of the CDK,
* with the certificate ARN stored in an SSM Parameter.
*/
export class ComponentStack extends Stack {
constructor(parent: App, name: string, props?: StackProps) {
super(parent, name, props);
new StaticWebsite(this, 'StaticWebsite', {
bucketConfiguration: {
bucketName: process.env.S3_BUCKET,
removalPolicy: RemovalPolicy.DESTROY,
disableUpload: false,
websiteIndexDocument: process.env.INDEX_PAGE,
websiteErrorDocument: process.env.ERROR_PAGE,
source: './html'
},
aliasConfiguration: {
domainName: process.env.DOMAIN as string,
names: [`${process.env.SUBDOMAIN}.${process.env.DOMAIN}`, `${process.env.DOMAIN}`],
acmCertRef: process.env.ACM_CERT_REF as string,
},
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment