> **Page index:** https://kmtest.yngvar-hey-dev.oslo.systems/llms.txt lists every page on this site, with a link to its Markdown version.
>
> **Beyond these docs:** Team Utviklerflyt's golden-path plugin for Claude Code answers golden path questions from the source code of the platform's templates, Terraform modules and workflows. [Golden path plugin for Claude Code](/set-up-your-machine/golden-path-plugin-for-claude-code/index.md) shows how to install it.

# `cloudfront-static-website`

<!-- DESCRIPTION BEGIN -->
Static website on S3 and CloudFront, with TLS and a custom domain.
<!-- DESCRIPTION END -->

!!! note
    This stack might take a **long time** to both **apply** and **destroy** due to the CloudFront distribution. Deployment typically takes around 5 minutes, while destruction can take 5-6 minutes.

!!! note
    This template also installs the [`cloudfront-static-website-data`](../cloudfront-static-website-data/) template, which creates the S3 buckets for content and logs. Apply the data stack first.

## Architecture

This template creates the CloudFront distribution and associated resources that work with the S3 buckets created by the [data stack](../cloudfront-static-website-data/):

- **CloudFront Distribution** - CDN with custom domain and TLS
- **Route53 Record** - DNS alias pointing to CloudFront
- **ACM Certificate** - TLS certificate for custom domain (us-east-1)
- **Deployment** (when `DeploymentPipelineV2.Enable: true`) - Terraform deploys the website bundle with the deployment Lambda function from the [`cicd-common`](../cicd-common/) template

The S3 buckets (content and logs) are created separately in the data stack to allow for independent lifecycle management.

## Features

- HTTPS-only with custom domain
- Client-side routing support (when `RedirectAllToIndex: true`) - requests that do not match a file get `RootObject` with status `200` (similar to [react-cors-spa](https://github.com/aws-samples/react-cors-spa))
- Optional URL rewriting (when `AppendIndexToDirectories: true`) - adds `index.html` to directory requests and URLs without extensions, based on [AWS CloudFront Functions sample](https://github.com/aws-samples/amazon-cloudfront-functions/tree/main/url-rewrite-single-page-apps)
- Configurable root and error objects via `RootObject` and `ErrorObject`

## Usage

See these guides in the Golden Path documentation:

- [Create a static website](https://kmtest.yngvar-hey-dev.oslo.systems/application/static-website/create-new-application/)
- [Set up CI/CD for a static website](https://kmtest.yngvar-hey-dev.oslo.systems/application/static-website/set-up-cicd/)

<!-- BOILERPLATE BEGIN -->
<!-- Generated by running `make docs` from the `boilerplate` dir) -->
<!-- Updated automatically in release PRs -->

## Variables

|           Name           |                                                                                                            Description                                                                                                             |  Type  |                 Default                 |Required|
|--------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|-----------------------------------------|--------|
|`Name`                    |Website name. Used as the subdomain, exposing the site at `https://<Name>.<Environment>.oslo.systems`.                                                                                                                              |`string`|``n/a``                                  |yes     |
|`RedirectAllToIndex`      |Serve `RootObject` with status `200` for every request that does not match a file, instead of the `ErrorObject` error page. Needed for single-page apps with client-side routing.                                                   |`bool`  |``false``                                |no      |
|`RootObject`              |The object served when the site root (`/`) is requested. Also the object that `RedirectAllToIndex` and `AppendIndexToDirectories` rewrite requests to.                                                                              |`string`|``index.html``                           |no      |
|`ErrorObject`             |The object served with status `404` when a requested file does not exist. Not used when `RedirectAllToIndex` is enabled.                                                                                                            |`string`|``404.html``                             |no      |
|`AppendIndexToDirectories`|Rewrite requests ending in `/` or without a file extension to append `/<RootObject>`, so `/about` serves `about/index.html`. Useful for static site generators that output one `index.html` per directory.                          |`bool`  |``false``                                |no      |
|`DeploymentPipelineV2`    |Deploy the website with the next-generation deployment pipeline. Replaces `IamForCicd`.                                                                                                                                             |`map`   |``{"Enable": false}``                    |no      |
|`IamForCicd`              |Deprecated: use `DeploymentPipelineV2` instead. Lets GitHub Actions in the website's repository (`GitHubRepo`, under the `oslokommune` org) deploy the site. The workflow must run in the GitHub environment `<Environment>-<Name>`.|`map`   |``{"Enable": false, "GitHubRepo": null}``|no      |

<!-- BOILERPLATE END -->
