@nona-creative/aws-cdk-s3-cloudfront
TypeScript icon, indicating that this package has built-in type declarations

2.12.0 • Public • Published

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 and CDK_DEFAULT_REGION are picked up from the AWS_PROFILE environment variable

  • As 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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.12.0
    21
    • latest

Version History

Package Sidebar

Install

npm i @nona-creative/aws-cdk-s3-cloudfront

Weekly Downloads

21

Version

2.12.0

License

MIT

Unpacked Size

87.7 kB

Total Files

30

Last publish

Collaborators

  • yesitsdave
  • syntaxza
  • rollyourowned
  • neilrussell6
  • ian-cawood