How to set KV environment variables in the dashboard?
I'm trying to use a Cloudflare Pages worker which I have stored in the functions folder of my Pages repository,.
This particular worker needs to access an KV-namespace - and in this instance, I'd like to set it through the dasboard but when I set environment variables, it doesn't seem like my Workers is able to pick them up...
15 Replies
https://developers.cloudflare.com/workers/configuration/bindings/ - this is the docs I am following, under
Configuration
Bindings Β· Cloudflare Workers docs
Interact with storage and other resources on the Cloudflare Developer Platform.
in the functions folder of my Pages repository,If it's under the Functions folder, it's a function, not a worker. Functions are technically Workers under the hood, but that's far abstracted from you. Worker Config Docs will not apply to Functions
@Chaika Oki, but how do I get the Functions to pick up the binding? A wrangler.toml file?
If you're trying to use
pages dev
(local dev) with your Function and a binding, there's docs on how to use those bindings locally here: https://developers.cloudflare.com/pages/platform/functions/bindings/Bindings Β· Cloudflare Pages docs
A binding enables your Pages Functions to interact with resources on the Cloudflare developer platform. Use bindings to integrate your Pages Functions β¦
@Chaika Just going to prod directly, no dev.
Would a
wrangler.toml
inside the functions folder (not in the root of the functions folder but inside the actual functions folder) do?
oh, then you'd just set it in your Pages Project
In Account Home, select Workers & Pages. Select your Pages project > Settings > Functions > KV namespace bindings > Add binding. Choose whether you would like to set up the binding in your Production or Preview environment. Give your binding a name under Variable name. Under KV namespace, select your desired namespace. You must repeat steps 5 and 6 for both the Production and Preview environments. Redeploy your project for the binding to take effect.no, wrangler.toml isn't used for Pages prod at all. In some cases dev uses it (which is confusing), but all production/live functions configuration has to be done in the dashboard
@Chaika ace! Just found it.
nice! Yea it's a fair bit confusing right now, CF has been talking about merging Workers & Pages for a bit which would be nice (although not exactly sure what that would look like), right now it can be confusing.
Functions are Workers with some of Pages magic on top like file based routing and such, and only support local dev (wrangler pages dev) and for deployments have to be configured entirely in the dash
I need to learn this anyway, some day I hope to work for CF π
Actually got quite far in an interview process but was a very senior management role and I probably feel better working closer to the code or the community π
@Chaika this work like a charm, I'm very thankful.
Nice! Well best of luck with that, whenever we get Convergence it'll be nice and help with a lot of these differences
What's Convergence?
Chaika is referencing the convergence of
Pages Functions
with Cloudflare Workers
.
They are both Workers under the hood, with Functions having some additional Pages magic, which confuses things a bit when trying to learn the platform.Convergence is a bit bigger then that, it'd be Pages and Workers together entirely: https://blog.cloudflare.com/pages-and-workers-are-converging-into-one-experience/
but yea you get the gist
The Cloudflare Blog
Bringing a unified developer experience to Cloudflare Workers and P...
Today weβre excited to announce that over the next year we will be working to bring together the best traits and attributes you know and love from each product into one powerful platform!
Pages has lots of very cool things like Git integration, preview deployments, free static asset serving, etc, but lacks all of the Worker Features, remote dev, and newer products like Logpush support. Workers has a Github Action you can use but no preview deployments outside of making other Workers for testing/staging (Which is what Wrangler Environment does), lots of trade offs
This is very useful, yes, I was a bit confused as I was mixing Workers and Pages Functions, I thought they were the same, yet there are a bit different ways and especially Pages is so neat to integrate with Github. Either way, I'm on CF for the long run. Keep advocating where I work that we don't really need AWS or GCP.
I find AWS in particular complicates things unnecessarily, and straight out lacks some of the most important elements wrt retail websites (bot protection etc).