> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formae.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Static website (S3 + CloudFront)

> An AWS infrastructure pattern, deployed with formae.

A static site served from an S3 website bucket, fronted by a CloudFront
distribution, with a Route 53 hosted zone and an alias record pointing at the
distribution. The bucket policy makes the objects publicly readable, the
distribution uses the bucket's website endpoint as its origin, and the alias
record resolves to the distribution's domain name.

```mermaid theme={"languages":{"custom":["/languages/pkl.json"]}}
flowchart LR
  target["aws-target"]:::tgt

  subgraph stack["static-website-stack"]
    direction LR
    bucket["Website bucket"]:::res
    policy["Bucket policy"]:::res
    dist["CloudFront distribution"]:::res
    zone["Route 53 hosted zone"]:::res
    record["Alias record"]:::res

    bucket --> policy
    bucket --> dist
    zone --> record
    dist --> record
  end

  target --> stack

  classDef tgt fill:#FF8201,stroke:#B25900,color:#ffffff
  classDef res fill:#FFF3E6,stroke:#FF8201,color:#02024B
  style stack fill:#ffffff,stroke:#02024B,stroke-width:2px,stroke-dasharray:6 4,color:#02024B
```

**Deploy.** Apply the example forma. formae brings up the bucket and its policy
before the distribution, and the hosted zone before the alias record:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae apply --mode reconcile \
  /opt/pel/formae/examples/formae-plugin-aws/static-website/main.pkl
```

**Verify.** Once the command completes, the distribution is under management:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae inventory resources --query="type:AWS::CloudFront::Distribution"
```

**Tear down.** Remove everything the forma created:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae destroy \
  /opt/pel/formae/examples/formae-plugin-aws/static-website/main.pkl
```

The full forma is in the
[static-website example](https://github.com/platform-engineering-labs/formae-plugin-aws/tree/main/examples/static-website).
