@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
Release files for cloudcomponents.cdk-static-website 2.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cloudcomponents.cdk-static-website-2.2.0.tar.gz | 151.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cloudcomponents.cdk_static_website-2.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 300.6 kB
Release files / cloudcomponents.cdk-static-website-2.2.0.tar.gz
| Download URL | cloudcomponents.cdk-static-website-2.2.0.tar.gz |
|---|---|
| Size | 151.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
795498e2644319ec66efd49da065cdb1b4bc971eba10cc6e49360a8df1c45510
|
|
BLAKE2b-256 checksum How to use checksums |
599300685c228f8254a26d4af444dea375f84559cdca2b2d46f2d057535fde88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / cloudcomponents.cdk_static_website-2.2.0-py3-none-any.whl
| Download URL | cloudcomponents.cdk_static_website-2.2.0-py3-none-any.whl |
|---|---|
| Size | 149.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
49818ac095064b15fcb5d6f04d02ac0a54f1b374fe39f57eca65338ebb4124f7
|
|
BLAKE2b-256 checksum How to use checksums |
f053b548dabcb27779d5430daa1fade70d750d3df0f3fb0c127607553a056136
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|