Skip to content

Latest commit

 

History

History
88 lines (58 loc) · 3.68 KB

File metadata and controls

88 lines (58 loc) · 3.68 KB
pcx_content_type title head description
configuration
Secrets
Store sensitive information, like API keys and auth tokens, in your Worker.

import { Render } from "~/components";

Background

Secrets are a type of binding that allow you to attach encrypted text values to your Worker. You cannot see secrets after you set them and can only access secrets via Wrangler or programmatically via the env parameter. Secrets are used for storing sensitive information like API keys and auth tokens. Secrets are available on the env parameter passed to your Worker's fetch event handler.

Local Development with Secrets

Secrets on deployed Workers

Adding secrets to your project

Via Wrangler

Secrets can be added through wrangler secret put or wrangler versions secret put commands.

wrangler secret put creates a new version of the Worker and deploys it immediately.

npx wrangler secret put <KEY>

If using gradual deployments, instead use the wrangler versions secret put command. This will only create a new version of the Worker, that can then be deploying using wrangler versions deploy.

:::note Wrangler versions before 3.73.0 require you to specify a --x-versions flag. :::

npx wrangler versions secret put <KEY>

Via the dashboard

To add a secret via the dashboard:

  1. Log in to Cloudflare dashboard and select your account.
  2. Select Workers & Pages.
  3. In Overview, select your Worker > Settings.
  4. Under Variables and Secrets, select Add.
  5. Select the type Secret, input a Variable name, and input its Value. This secret will be made available to your Worker but the value will be hidden in Wrangler and the dashboard.
  6. (Optional) To add more secrets, select Add variable.
  7. Select Deploy to implement your changes.

Delete secrets from your project

Via Wrangler

Secrets can be deleted through wrangler secret delete or wrangler versions secret delete commands.

wrangler secret delete creates a new version of the Worker and deploys it immediately.

npx wrangler secret delete <KEY>

If using gradual deployments, instead use the wrangler versions secret delete command. This will only create a new version of the Worker, that can then be deploying using wrangler versions deploy.

npx wrangler versions secret delete <KEY>

Via the dashboard

To delete a secret from your Worker project via the dashboard:

  1. Log in to Cloudflare dashboard and select your account.
  2. Select Workers & Pages.
  3. In Overview, select your Worker > Settings.
  4. Under Variables and Secrets, select Edit.
  5. In the Edit drawer, select X next to the secret you want to delete.
  6. Select Deploy to implement your changes.
  7. (Optional) Instead of using the edit drawer, you can click the delete icon next to the secret.

Related resources