Update Worker's Env Var through the API
I would like to be able to update a Cloudflare worker's env var through the API. It seems like there is a REST endpoint, that allows me to upload a whole new script for a worker + the environment variables, but no endpoint to just update the environment variables themselves + redeploy.
Updating the whole script is way too complex for us, as well as error prone, is there a workaround for this? Would it be better to potentially use KV as a storage mechanism for these settings (postgres connection strings and JWT tokens) if env vars are not able to be updated standalone through the API? Or am I missing something in the documentation?
3 Replies
Unfortunately I'm not aware of any way to update env vars without also updating the worker script. Even the dash does it this way behind the scenes.
If I wanted to update the worker's env var from an entirely separate process, then it wouldn't have access to the worker's codebase. Wonder if this is a feature request
You could pull the worker's code from the API then re-send it with your updated config. I believe that's what the dashboard does if you watch the network requests. It's not idea, but should work