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.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | de61249b4e7fe683bcbcb08783780d0014f8933c694f38bf3e89488efde11cd5 |
|
MD5 | 20390896bc72ffe1964fd934c8f03ced |
|
BLAKE2b-256 | 833e14ed86ee99d28b055d5fd81e1379e990d4fc85606fa3261ad1e04d45fc60 |
Close
Hashes for cloudcomponents.cdk_static_website-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f029f1b34007e7f8f9b32d3aa54f358d70e7e60af3524a5b17438e2af8029f65 |
|
MD5 | 982187ceb0d2bb283253360e71cac5d2 |
|
BLAKE2b-256 | b8f151c521f8701acf16c42841a0ebf32cd1a989945130dd81ece46633219644 |