Skip to main content

CDK Static Website Construct

This package contains a high-level CDK construct for describing the infrastructure of a static website. The construct also features a deploy method to deploy static assets for the website and invalidate the CloudFront distribution.

The CDK construct creates the private S3 bucket, where the website is hosted. The contents of the bucket are exposed through a CloudFront distribution. Rather than allowing public access to the bucket, OAI is used to allow access from CloudFront only.

Further reading: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html

This construct also creates the necessary Route 53 records to route requests to the CloudFront distribution. It also configures the distribution with a supplied SSL certificate.

Pre-requisites

This construct works with recent versions of CDK v2. There are similar constructs on PyPI for v1 - one of the motivations for this package was to support v2.

If you are not familiar with CDK, have a read here.

Registering a domain name, creating the hosted zone in Route 53 and creating the SSL certificate are not in scope for this construct. These can be created manually or through other automated ways on AWS.

Note, the certificate needs to be created in North Virginia (us-east-1).

Once these are created, you should have all the necessary inputs: the domain name, domain certificate ARN, the hosted zone ID and the hosted zone name.

How to use it?

Install the package using your favourite package manager, e.g.

pip install cdk-static-site

Within your stack, instantiate the construct

from static_site import StaticSite

site = StaticSite(
    scope=self,
    construct_id="StaticSite",
    site_domain_name=site_domain_name,
    hosted_zone_id=hosted_zone_id,
    hosted_zone_name=hosted_zone_name,
    domain_certificate_arn=domain_certificate_arn,
)

and finally, deploy the static contents by supplying the directory path to deploy:

from pathlib import Path

contents_path = Path.cwd() / "public"  # or wherever your assets are located
site.deploy(contents_path.as_posix())

Contribution

If you find any issues, or have suggestions to improve the construct, feel free to open an issue/PR.

Metadata

Release files for cdk-static-site 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cdk-static-site 0.1.2
File Size Uploaded Provenance
cdk-static-site-0.1.2.tar.gz 4.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cdk-static-site 0.1.2
File Interpreter ABI Platform
cdk_static_site-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 8.7 kB

Release files / cdk-static-site-0.1.2.tar.gz

Download URL cdk-static-site-0.1.2.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8c0898285875019a63f01ae70558483c6c741cda42739f4afdd9d1bce71d73f2
BLAKE2b-256 checksum
How to use checksums
8776cdc7c2c6c8513af120d0886ea141217a2dbeef13b3613628a576f1f9a91c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.9.7 Darwin/21.1.0

Release files / cdk_static_site-0.1.2-py3-none-any.whl

Download URL cdk_static_site-0.1.2-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b5caa445260ce7c880f625d3495850d64a75b6bac576e8b98cd640a751057ef
BLAKE2b-256 checksum
How to use checksums
fbe93189e5d38354e9585359d57cd9971899b9b40bb17151a5df86a20e2a4298
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.9.7 Darwin/21.1.0

Security for cdk-static-site 0.1.2

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.

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