1.9.0 • Published 4 years ago

@neweracode/cdk-static-site v1.9.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

NewEraCode Static Website Component

Description

An AWS CDK construct that creates 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.

Usage

Install

npm i @neweracode/cdk-static-website

Import

NodeJS

const cds = require('@neweracode/cdk-static-site');
new cds.CdkStaticSite(....)

TypeScript / Babel

import { CdkStaticSite } from '@neweracode/cdk-static-site';

Example:

import { App, RemovalPolicy, Stack, StackProps } from '@aws-cdk/core';
import { CdkStaticSite } from './cdk-static-site';

export class ComponentStack extends Stack {
    public constructor(parent: App, name: string, props?: StackProps) {
        super(parent, name, props);

        new CdkStaticSite(this, 'StaticWebsite', {
            bucketConfiguration: {
                bucketName: "myBucket",
                removalPolicy: RemovalPolicy.RETAIN,
                websiteIndexDocument: "index.html",
                websiteErrorDocument: "error.html",
                source: "websiteFiles" // local directory with static files
            },
            aliasConfiguration: {
                domainName: "domain.com"
                siteDomain: "example.domain.com",
                acmCertRef: "arn:aws:acm:us-east-1:....."
            },
        });
    }
}