项目作者: ukautz

项目描述 :
AWS CDK pattern / solution construct implementing a static website hosting with CloudFront + S3 + ACM certificate
高级语言: TypeScript
项目地址: git://github.com/ukautz/aws-cdk-static-website.git
创建时间: 2021-03-03T22:58:05Z
项目社区:https://github.com/ukautz/aws-cdk-static-website

开源协议:

下载


AWS CDK: Static Website

An AWS CDK Level 3 construct that implements an opinionated static website in AWS using:

  • A public readable S3 bucket, that mirrors the contents of local directory of .html files and related assets
  • A CloudFront distribution, that caches the S3 delivery and enforces HTTPS
  • Route53 record(s) that route one or multiple public domains to S3
  • A certificate for the provided public domain(s) for HTTPS

Diagram

Usage

Install package:

  1. $ npm install @ukautz/aws-cdk-static-website

Then in your stack:

  1. import * as cdk from 'aws-cdk-lib';
  2. import { aws_route53 as route53 } from 'aws-cdk-lib';
  3. import { StaticWebsite } from '@ukautz/aws-cdk-static-website';
  4. import { Construct } from 'constructs';
  5. export class YourStack extends cdk.Stack {
  6. constructor(scope: Construct, id: string, props?: cdk.Stack) {
  7. super(scope, id, props);
  8. // load (or create) a hosted zone, in which the record(s) will be created
  9. const hostedZone = route53.HostedZone.fromLookup(this, 'HostedZone', {
  10. domainName: 'your-domain.tld',
  11. });
  12. // create a static website, that uploads and serves contents from a local folder
  13. new StaticWebsite(this, 'StaticWebsite', {
  14. directory: '/path/to/where/your/contents/are',
  15. domain: 'blog.your-domain.tld',
  16. hostedZone,
  17. });
  18. }
  19. }

Note: See the StaticWebsiteProps interface for all available properties.

See also