Automatically provision Cloudflare resources when deploying a Worker with Wrangler (Beta)
You can now automatically provision Cloudflare resources as part of your deployment. You no longer need to manually run separate commands to create resources that do not yet exist on your account prior to deploying.
With resource provisioning, if your Wrangler configuration file includes a KV namespace, D1 database, or R2 bucket that does not yet exist, Wrangler will detect and create these resources upon deployment. This is done by adding the experimental -–x-provision
flag to your commands.
You can set up your Wrangler configuration file like the following:
{ "kv_namespaces": [ { "binding": "MY_KV" } ], "r2_buckets": [ { "binding": "MY_R2" } ], "d1_databases": [ { "binding": "MY_D1" } ]}
[[kv_namespaces]]binding = "MY_KV"
[[r2_buckets]]binding = "MY_R2"
[[d1_databases]]binding = "MY_D1"
When using the experimental -–x-provision
flag, the id
field for KV and D1 and the bucket_name
for R2 are optional in your wrangler configuration.
When developing locally, you can interact with local versions of any KV, D1, R2 resources configured in your Wrangler configuration file by running:
npx wrangler dev –-x-provision
pnpm wrangler dev –-x-provision
yarn wrangler dev –-x-provision
When you're ready to deploy, run:
npx wrangler deploy –-x-provision
pnpm wrangler deploy –-x-provision
yarn wrangler deploy –-x-provision
Upon deploy, Wrangler will automatically create the resources that do not yet exist on your account and bind them to your Worker. Each newly created resource will be named with the format <worker-name>-<binding-name>
by default.
$ wrangler deploy --x-provision ⛅️ wrangler 3.109.0--------------------
Total Upload: 0.29 KiB / gzip: 0.22 KiB
The following bindings need to be provisioned:- KV Namespaces: - MY_KV- D1 Databases: - MY_D1- R2 Buckets: - MY_R2
...
🎉 All resources provisioned, continuing with deployment...
Your worker has access to the following bindings:- KV Namespaces: - MY_KV: ...- D1 Databases: - MY_D1: ...- R2 Buckets: - MY_R2: ...Uploaded my-workerDeployed my-worker triggers https://my-worker.workers.devCurrent Version ID: ...
Resource provisioning is currently in beta. Drop us a note in the Cloudflare Developers Discord ↗ in the Wrangler channel ↗ and tell us what you think.