> ## 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.

# CloudFront edge

> An AWS infrastructure pattern, deployed with formae.

A minimal CloudFront edge stack that wires together the full set of edge
building blocks: an S3 origin bucket reached through an origin access control, a
CloudFront function backed by a key value store, and cache, origin request, and
response headers policies. The distribution references all of them.

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

  subgraph stack["cloudfront-edge-minimal"]
    direction LR
    bucket["Origin bucket"]:::res
    kvs["Key value store"]:::res
    fn["CloudFront function"]:::res
    cp["Cache policy"]:::res
    orp["Origin request policy"]:::res
    rhp["Response headers policy"]:::res
    oac["Origin access control"]:::res
    dist["Distribution"]:::res

    kvs --> fn
    bucket --> dist
    oac --> dist
    cp --> dist
    orp --> dist
    rhp --> dist
    fn --> dist
  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 creates the policies, function, key
value store, and origin bucket before the distribution that references them:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae apply --mode reconcile \
  /opt/pel/formae/examples/formae-plugin-aws/cloudfront-edge-minimal/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/cloudfront-edge-minimal/main.pkl
```

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