Workers (3)·续3
The following is an example of creating, updating, and deleting secrets from a JSON file redirected to stdin. Set a key to null to delete it.
{
"secret-name-1": "secret-value-1",
"secret-name-2": "secret-value-2",
"secret-name-3": null
}
npx wrangler secret bulk < secrets.json
🌀 Processing the secrets for the Worker "script-name"
✨ Successfully created secret for key: secret-name-1
✨ Successfully created secret for key: secret-name-2
💥 Successfully deleted secret for key: secret-name-3
Finished processing secrets file:
✨ 2 secrets successfully created
💥 1 secrets successfully deleted
tail
🦚 Start a log tailing session for a Worker
npmyarnpnpm
npx wrangler tail [WORKER]
yarn wrangler tail [WORKER]
pnpm wrangler tail [WORKER]
[WORKER]stringName or route of the worker to tail--format"json" | "pretty"The format of log entries--status"ok" | "error" | "canceled"Filter by invocation status--headerstringFilter by HTTP header--methodstringFilter by HTTP method--sampling-ratenumberAdds a percentage of requests to log sampling rate--searchstringFilter by a text match in console.log messages--ipstringFilter by the IP address the request originates from. Use "self" to filter for your own IP--version-idstringFilter by Worker version
<details>
<summary>
Global flags
</summary>
- <code>--v</code><code>boolean</code> alias: --version
Show version number - <code>--cwd</code><code>string</code>Run as if Wrangler was started in the specified directory instead of the current working directory - <code>--config</code><code>string</code> alias: --c
Path to Wrangler configuration file - <code>--env</code><code>string</code> alias: --e
Environment to use for operations, and for selecting .env and .dev.vars files - <code>--env-file</code><code>string</code>Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files - <code>--install-skills</code><code>boolean</code> default: false
Install Cloudflare skills for detected AI coding agents before running the command - <code>--profile</code><code>string</code>Use a specific auth profile
</details>
After starting wrangler tail, you will receive a live feed of console and exception logs for each request your Worker receives.
If your Worker has a high volume of traffic, the tail might enter sampling mode. This will cause some of your messages to be dropped and a warning to appear in your tail logs. To prevent messages from being dropped, add the options listed above to filter the volume of tail messages.
Note
It may take up to 1 minute (60 seconds) for a tail to exit sampling mode after adding an option to filter tail messages.
If sampling persists after using options to filter messages, consider using instant logs.
versions
Note
The minimum required wrangler version to use these commands is 3.40.0. For versions before 3.73.0, you will need to add the --x-versions flag.
versions upload
Upload a new version of your Worker that is not deployed immediately.
npmyarnpnpm
npx wrangler versions upload [PATH]
yarn wrangler versions upload [PATH]
pnpm wrangler versions upload [PATH]
[PATH]stringThe path to an entry point for your Worker or a directory of static assets--namestringName of the Worker--tagstringA tag for this Worker Version--messagestringA descriptive message for this Worker Version--no-bundlebooleandefault: false
Skip internal build steps and directly upload Worker
- --outdir string Output directory for the bundled Worker
- --outfile string Output file for the bundled worker
- --compatibility-date string Date to use for compatibility checks
- --compatibility-flags string alias: --compatibility-flag
Flags to use for compatibility checks
- --latest boolean default: false
Use the latest compatibility date supported by this version of Wrangler
- --assets string Static assets to be served. Replaces Workers Sites.
- --var string A key-value pair to be injected into the script as a variable
- --define string A key-value pair to be substituted in the script
- --alias string A module pair to be substituted in the script
- --jsx-factory string The function that is called for each JSX element
- --jsx-fragment string The function that is called for each JSX fragment
- --tsconfig string Path to a custom tsconfig.json file
- --minify boolean Minify the Worker
- --upload-source-maps boolean Include source maps when uploading this Worker (defaults to true)
- --dry-run boolean Compile a project and run checks without actually uploading the Worker
- --secrets-file string Path to a file containing secrets to upload with the version (JSON or .env format). Applies additively with secrets from previous deployments - omitted secrets will not be deleted.
- --keep-vars boolean default: false
When not used (or set to false), Wrangler will delete all vars before setting those found in the Wrangler configuration. When used (and set to true), the environment variables are not deleted before the deployment. If you set variables via the dashboard you probably want to use this flag. Note that secrets are never deleted by deployments.
- --strict boolean default: false
Enables strict mode, which prevents uploads when there are conflicting remote changes.
- --preview-alias string Name of an alias for this Worker version
<details>
<summary>
Global flags
</summary>
- <code>--v</code><code>boolean</code> alias: --version
Show version number - <code>--cwd</code><code>string</code>Run as if Wrangler was started in the specified directory instead of the current working directory - <code>--config</code><code>string</code> alias: --c
Path to Wrangler configuration file - <code>--env</code><code>string</code> alias: --e
Environment to use for operations, and for selecting .env and .dev.vars files - <code>--env-file</code><code>string</code>Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files - <code>--install-skills</code><code>boolean</code> default: false
Install Cloudflare skills for detected AI coding agents before running the command - <code>--profile</code><code>string</code>Use a specific auth profile
</details>
versions deploy
Deploy a previously created version of your Worker all at once or create a gradual deployment to incrementally shift traffic to a new version by following an interactive prompt.
npmyarnpnpm
npx wrangler versions deploy [VERSION-SPECS]
yarn wrangler versions deploy [VERSION-SPECS]
pnpm wrangler versions deploy [VERSION-SPECS]
--durable-objects-code-update-modestringHow to update Durable Object code: immediate, or deferred followed by a maximum delay (for example, deferred 30s)--namestringName of the worker--version-idstringWorker Version ID(s) to deploy--percentagenumberPercentage of traffic to split between Worker Version(s) (0-100)[VERSION-SPECS]stringShorthand notation to deploy Worker Version(s) [\<version-id>@\<percentage>..]. Omitted percentages share the remaining traffic.--version-tagstringWorker Version tag(s) to deploy, resolved to a Version ID against the deployable versions. Supports the shorthand notation [\<version-tag>@\<percentage>..].--messagestringDescription of this deployment (optional)--yesbooleanalias: --ydefault: false
Automatically accept defaults to prompts
- --dry-run boolean default: false
Don't actually deploy
<details>
<summary>
Global flags
</summary>
- <code>--v</code><code>boolean</code> alias: --version
Show version number - <code>--cwd</code><code>string</code>Run as if Wrangler was started in the specified directory instead of the current working directory - <code>--config</code><code>string</code> alias: --c
Path to Wrangler configuration file - <code>--env</code><code>string</code> alias: --e
Environment to use for operations, and for selecting .env and .dev.vars files - <code>--env-file</code><code>string</code>Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files - <code>--install-skills</code><code>boolean</code> default: false
Install Cloudflare skills for detected AI coding agents before running the command - <code>--profile</code><code>string</code>Use a specific auth profile
</details>
Note
The non-interactive version of this prompt is: wrangler versions deploy version-id-1@percentage-1% version-id-2@percentage-2 -y
For example: wrangler versions deploy 095f00a7-23a7-43b7-a227-e4c97cab5f22@10% 1a88955c-2fbd-4a72-9d9b-3ba1e59842f2@90% -y
versions list
Retrieve details for the 10 most recent versions. Details include Version ID, Created on, Author, Source, and optionally, Tag or Message.
npmyarnpnpm
npx wrangler versions list
yarn wrangler versions list
pnpm wrangler versions list
--namestringName of the Worker--jsonbooleandefault: false
Display output as JSON
<details>
<summary>
Global flags
</summary>
- <code>--v</code><code>boolean</code> alias: --version
Show version number - <code>--cwd</code><code>string</code>Run as if Wrangler was started in the specified directory instead of the current working directory - <code>--config</code><code>string</code> alias: --c
Path to Wrangler configuration file - <code>--env</code><code>string</code> alias: --e
Environment to use for operations, and for selecting .env and .dev.vars files - <code>--env-file</code><code>string</code>Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files - <code>--install-skills</code><code>boolean</code> default: false
Install Cloudflare skills for detected AI coding agents before running the command - <code>--profile</code><code>string</code>Use a specific auth profile
</details>
versions view
View the details of a specific version of your Worker
npmyarnpnpm
npx wrangler versions view <VERSION-ID>
yarn wrangler versions view <VERSION-ID>
pnpm wrangler versions view <VERSION-ID>
<VERSION-ID>stringrequired
The Worker Version ID to view
- --name string Name of the worker
- --json boolean default: false
Display output as JSON
<details>
<summary>
Global flags
</summary>
- <code>--v</code><code>boolean</code> alias: --version
Show version number - <code>--cwd</code><code>string</code>Run as if Wrangler was started in the specified directory instead of the current working directory - <code>--config</code><code>string</code> alias: --c
Path to Wrangler configuration file - <code>--env</code><code>string</code> alias: --e
Environment to use for operations, and for selecting .env and .dev.vars files - <code>--env-file</code><code>string</code>Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files - <code>--install-skills</code><code>boolean</code> default: false
Install Cloudflare skills for detected AI coding agents before running the command - <code>--profile</code><code>string</code>Use a specific auth profile
</details>
versions secret put
Create or update a secret variable for a Worker
npmyarnpnpm
npx wrangler versions secret put [KEY]
yarn wrangler versions secret put [KEY]
pnpm wrangler versions secret put [KEY]
[KEY]stringThe variable name to be accessible in the Worker--namestringName of the Worker--messagestringDescription of this deployment--tagstringA tag for this version
<details>
<summary>
Global flags
</summary>
- <code>--v</code><code>boolean</code> alias: --version
Show version number - <code>--cwd</code><code>string</code>Run as if Wrangler was started in the specified directory instead of the current working directory - <code>--config</code><code>string</code> alias: --c
Path to Wrangler configuration file - <code>--env</code><code>string</code> alias: --e
Environment to use for operations, and for selecting .env and .dev.vars files - <code>--env-file</code><code>string</code>Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files - <code>--install-skills</code><code>boolean</code> default: false
Install Cloudflare skills for detected AI coding agents before running the command - <code>--profile</code><code>string</code>Use a specific auth profile
</details>
versions secret delete
Delete a secret variable from a Worker
npmyarnpnpm
npx wrangler versions secret delete [KEY]
yarn wrangler versions secret delete [KEY]
pnpm wrangler versions secret delete [KEY]
[KEY]stringThe variable name to be accessible in the Worker--namestringName of the Worker--messagestringDescription of this deployment--tagstringA tag for this version
<details>
<summary>
Global flags
</summary>
- <code>--v</code><code>boolean</code> alias: --version
Show version number - <code>--cwd</code><code>string</code>Run as if Wrangler was started in the specified directory instead of the current working directory - <code>--config</code><code>string</code> alias: --c
Path to Wrangler configuration file - <code>--env</code><code>string</code> alias: --e
Environment to use for operations, and for selecting .env and .dev.vars files - <code>--env-file</code><code>string</code>Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files - <code>--install-skills</code><code>boolean</code> default: false
Install Cloudflare skills for detected AI coding agents before running the command - <code>--profile</code><code>string</code>Use a specific auth profile
</details>
versions secret bulk
Create, update, or delete multiple secret variables for a Worker
npmyarnpnpm
npx wrangler versions secret bulk [FILE]
yarn wrangler versions secret bulk [FILE]
pnpm wrangler versions secret bulk [FILE]
[FILE]stringThe file of key-value pairs to create, update, or delete, as JSON in form {"key": "value", ...} or .env file in the form KEY=VALUE. Set a key to null in the JSON file to delete it. Deletion is not supported with .env files. If omitted, Wrangler expects to receive input from stdin rather than a file.--namestringName of the Worker--messagestringDescription of this deployment--tagstringA tag for this version
