Metadata-Version: 2.1
Name: cdk-static-site
Version: 0.1.0
Summary: 
Home-page: https://github.com/davidsteiner/cdk-static-site
Author: David Steiner
Author-email: david_j_steiner@yahoo.co.nz
Requires-Python: >=3.9,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.9
Requires-Dist: aws-cdk-lib (>=2.28,<3.0)
Description-Content-Type: text/markdown

# 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

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.

```shell
pip install cdk-static-site
```

Within your stack, instantiate the construct
```python
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`:

```python
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.

