Skip to content

Commit 5976688

Browse files
committed
docs: add Cloudflare API token guide
1 parent fd55cdb commit 5976688

5 files changed

Lines changed: 69 additions & 8 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: Cloudflare API Token
3+
description: Set up the Cloudflare token SST uses for deployments.
4+
---
5+
6+
SST needs a Cloudflare API token and account ID before it can deploy to Cloudflare.
7+
8+
Use a Cloudflare [account token](https://developers.cloudflare.com/fundamentals/api/get-started/account-owned-tokens/). It works better for automation because it is not tied to one user.
9+
10+
Before you run `sst dev` or `sst deploy`, set:
11+
12+
```bash
13+
export CLOUDFLARE_API_TOKEN=aaaaaaaa_aaaaaaaaaaaa_aaaaaaaa
14+
export CLOUDFLARE_DEFAULT_ACCOUNT_ID=aaaaaaaa_aaaaaaaaaaaa_aaaaaaaa
15+
```
16+
17+
---
18+
19+
## 1. Create the token
20+
21+
In the Cloudflare dashboard, go to **Manage Account** > **API Tokens** and create an **Account token**.
22+
23+
Start with the **Edit Cloudflare Workers** template. Then add these permissions.
24+
25+
- **Account - D1 - Edit**
26+
- **Zone - DNS - Edit**
27+
28+
If your app uses other Cloudflare products, add the permissions those features need.
29+
30+
If you use Hyperdrive, also add:
31+
32+
- **Account - Hyperdrive - Edit**
33+
34+
---
35+
36+
## 2. Scope the token
37+
38+
Give the token access to the account you want SST to manage.
39+
40+
If you are using Cloudflare DNS with SST, include the zones SST should update.
41+
42+
---
43+
44+
## 3. Set the account ID
45+
46+
Set `CLOUDFLARE_DEFAULT_ACCOUNT_ID` to the Cloudflare account ID SST should use.
47+
48+
If you leave it unset, SST falls back to the first account Cloudflare returns for that token.
49+
50+
---
51+
52+
## 4. Add the credentials to your environment
53+
54+
Set these variables in your shell, `.env`, CI, or SST Console environment before you deploy.
55+
56+
:::note
57+
Do not store these with `sst secret` for the initial Cloudflare deploy. SST reads them before it can create resources.
58+
:::

www/src/content/docs/docs/providers.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ Most providers will read your credentials from the environment. For example, for
114114

115115
```bash
116116
export CLOUDFLARE_API_TOKEN=aaaaaaaa_aaaaaaaaaaaa_aaaaaaaa
117+
export CLOUDFLARE_DEFAULT_ACCOUNT_ID=aaaaaaaa_aaaaaaaaaaaa_aaaaaaaa
117118
```
118119

120+
Follow the [Cloudflare API token guide](/docs/cloudflare-api-token/) for the recommended setup.
121+
119122
However, some providers also allow you to pass in the credentials through the config.
120123

121124
```ts title="sst.config.ts"

www/src/content/docs/docs/start/cloudflare/hono.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ We are going to build an API with Hono, add an R2 bucket for file uploads, and d
99
You can [view the source](https://github.com/sst/sst/tree/dev/examples/cloudflare-hono) of this example in our repo.
1010
:::
1111

12-
Before you get started, make sure to [Create your Cloudflare API token](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/).
12+
Before you get started, [create your Cloudflare API token](/docs/cloudflare-api-token/).
1313

1414
---
1515

@@ -37,9 +37,9 @@ Select the defaults and pick **Cloudflare**. This'll create a `sst.config.ts` fi
3737

3838
---
3939

40-
#### Set the Cloudflare API token
40+
#### Set the Cloudflare credentials
4141

42-
You can save your Cloudflare API token in a `.env` file or just set it directly.
42+
Set the token and account ID in your shell or `.env` file.
4343

4444
```bash
4545
export CLOUDFLARE_API_TOKEN=aaaaaaaa_aaaaaaaaaaaa_aaaaaaaa

www/src/content/docs/docs/start/cloudflare/trpc.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ We are going to build a [tRPC](https://trpc.io) API, a simple client, and deploy
99
You can [view the source](https://github.com/sst/sst/tree/dev/examples/cloudflare-trpc) of this example in our repo.
1010
:::
1111

12-
Before you get started, make sure to [Create your Cloudflare API token](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/).
12+
Before you get started, [create your Cloudflare API token](/docs/cloudflare-api-token/).
1313

1414
---
1515

@@ -37,7 +37,7 @@ Select the defaults and pick **Cloudflare**. This'll create a `sst.config.ts` fi
3737

3838
---
3939

40-
#### Set the Cloudflare API token
40+
#### Set the Cloudflare credentials
4141

4242
You can save your Cloudflare API token in a `.env` file or just set it directly.
4343

www/src/content/docs/docs/start/cloudflare/worker.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ We are going to build an API with a Cloudflare Worker, add an R2 bucket for file
99
You can [view the source](https://github.com/sst/sst/tree/dev/examples/cloudflare-worker) of this example in our repo.
1010
:::
1111

12-
Before you get started, make sure to [Create your Cloudflare API token](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/).
12+
Before you get started, [create your Cloudflare API token](/docs/cloudflare-api-token/).
1313

1414
---
1515

@@ -37,9 +37,9 @@ Select the defaults and pick **Cloudflare**. This'll create a `sst.config.ts` fi
3737

3838
---
3939

40-
#### Set the Cloudflare API token
40+
#### Set the Cloudflare credentials
4141

42-
You can save your Cloudflare API token in a `.env` file or just set it directly.
42+
Set the token and account ID in your shell or `.env` file.
4343

4444
```bash
4545
export CLOUDFLARE_API_TOKEN=aaaaaaaa_aaaaaaaaaaaa_aaaaaaaa

0 commit comments

Comments
 (0)