@nona-creative/aws-cdk-s3-cloudfront
v2.12.0
Published
AWS CDK Construct for a static site. Provides S3, CloudFront, ACM, Route53, and subdomain redirects
Downloads
19
Readme
AWS CDK S3 Cloudfront Construct
This package provides a CDK construct that creates a Cloudfront distribution which serves content from S3 and is integrated with Route 53 and ACM. Specifically, it:
- Creates a private S3 bucket
- Creates a CloudFront distribution for that bucket
- Optionally creates a Route53 record pointing to that bucket
- Optionally creates a certificate for the distribution if a domain name is used (can use existing)
- Optionally adds subsomain redirects, .e.g. www.nona.digital redirects to the main nona.digital
- Optionally uploads content file to the S3 bucket and invalidates the distribution if it is already existing
Versioning
The minor version of the package is synchronized to the CDK version used.
Prerequisites
- An aws account and relevant profile configured
Example usage
new S3CloudFront(this, 'S3CloudFront', {
domain: {
domainName: 'example.nona.digital', // The domain name's TLD must be an existing hosted zone in Route53
tld: 'nona.digital',
},
subdomainRedirects: ['www'],
bucketName: 'examplenonadigital',
error404Document: '404.html',
})
Notes:
You need to have the correct AWS_PROFILE environment variable set as the
CDK_DEFAULT_ACCOUNT
andCDK_DEFAULT_REGION
are picked up from theAWS_PROFILE
environment variableAs the bucket is private and does not use S3 hosting, you need to add an edge lambda to serve index documents. The aws-cdk-standard-cloudfront-lambdas package provides these.
See example app for a complete example