Skip to main content

cloudcomponents Logo

@cloudcomponents/cdk-static-website

Build Status cdkdx typescript python Mentioned in Awesome CDK

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

MIT

Metadata

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)

Source distribution for cloudcomponents.cdk-static-website 2.2.0
File Size Uploaded Provenance Actions
cloudcomponents.cdk-static-website-2.2.0.tar.gz 151.2 kB Without provenance Details for cloudcomponents.cdk-static-website-2.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cloudcomponents.cdk-static-website 2.2.0
File Interpreter ABI Platform Actions
cloudcomponents.cdk_static_website-2.2.0-py3-none-any.whl Python 3 none any Details for cloudcomponents.cdk_static_website-2.2.0-py3-none-any.whl

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

Security for cloudcomponents.cdk-static-website 2.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page