Cdk component that creates a static website using S3, configures CloudFront (CDN) and maps a custom domain via Route53 (DNS)
Project description
@cloudcomponents/cdk-static-website
Cdk component that creates a static website using S3, configures CloudFront (CDN) and maps a custom domain via Route53 (DNS)
Install
TypeScript/JavaScript:
npm i @cloudcomponents/cdk-static-website
Python:
pip install cloudcomponents.cdk-static-website
How to use
import { StaticWebsite } from '@cloudcomponents/cdk-static-website';
import { RemovalPolicy, Stack, StackProps, aws_route53 } from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class StaticWebsiteStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps) {
super(scope, id, props);
const hostedZone = aws_route53.HostedZone.fromLookup(this, 'HostedZone', {
domainName: 'cloudcomponents.org',
});
new StaticWebsite(this, 'StaticWebsite', {
hostedZone,
domainNames: ['cloudcomponents.org', 'www.cloudcomponents.org'],
removalPolicy: RemovalPolicy.DESTROY,
});
}
}
Single page application (SPA)
import { StaticWebsite } from '@cloudcomponents/cdk-static-website';
import { RemovalPolicy, Stack, StackProps, aws_route53 } from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class StaticWebsiteStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps) {
super(scope, id, props);
const hostedZone = aws_route53.HostedZone.fromLookup(this, 'HostedZone', {
domainName: 'cloudcomponents.org',
});
new StaticWebsite(this, 'StaticWebsite', {
hostedZone,
domainNames: ['cloudcomponents.org', 'www.cloudcomponents.org'],
errorResponses: [
{
httpStatus: 404,
responseHttpStatus: 200,
ttl: props.ttl ?? Duration.seconds(300),
responsePagePath: '/index.html',
},
],
removalPolicy: RemovalPolicy.DESTROY,
});
}
}
Lambda at edge
import { StaticWebsite } from '@cloudcomponents/cdk-static-website';
import { OriginMutation } from '@cloudcomponents/cdk-lambda-at-edge-pattern';
import { RemovalPolicy, Stack, StackProps, aws_route53 } from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class StaticWebsiteStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps) {
super(scope, id, props);
const hostedZone = aws_route53.HostedZone.fromLookup(this, 'HostedZone', {
domainName: 'cloudcomponents.org',
});
const originMutation = new OriginMutation(stack, 'OriginMutation');
new StaticWebsite(this, 'StaticWebsite', {
hostedZone,
domainNames: ['cloudcomponents.org', 'www.cloudcomponents.org'],
edgeLambdas: [originMutation],
removalPolicy: RemovalPolicy.DESTROY,
});
}
}
API Reference
See API.md.
Example
See more complete examples.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for cloudcomponents.cdk-static-website-2.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29bec79a22f35b7335ace5e0ccb6b8cb00e31792087f2a6a22ece85f81b4e2fe |
|
MD5 | 4dab2fd9a3049ba977af9c58f9caa56b |
|
BLAKE2b-256 | aee0b58e1e965b197f4eca1c27d0d3c3400f296afa6bad82b7ca2c8d43afab47 |
Close
Hashes for cloudcomponents.cdk_static_website-2.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcebb03e6208ccb581e14a152aee7ef6903b92715e221c979460c91accaa6077 |
|
MD5 | 5062f1a70d974eaf16e0eedcb9f7aaeb |
|
BLAKE2b-256 | 42e040f30418b02aaedd4ca8ddac514a4a5cd56e62150756d90eabde7c8259be |