KV namespace binding at environment level

I’m using wrangler to deploy worker in my CI pipeline, but I have hit an issue where I need to bind the kv-namespace at environment level. From what I can see this doesn’t look possible. I thought it might be something that I could achieve via the API if not toml but this also looks to be deprecated in V4 api.

This is what I was hoping was possible:

[env.prod]
  [[kv-namespaces]]
  binding = "workerStore"
  id = "<production_id>"
[env.staging]
  [[kv-namespaces]]
  binding = "workerStore"
  id = "<staging_id>"

Any help on this is much appreciated, as currently it looks like the tooling around workers is deosn’t really work for CI. I can’t see the point of having wrangler, if I still need to do a lot of the set-up in the dashboard.

Found the docs for this https://github.com/cloudflare/wrangler/blob/master/docs/content/kv_commands.md

Rather than delete this post I will add the link for future searchers of this issue. Docs can be pretty hard to navigate around sometimes.

[env.prod]
account_id = "<cloudflareAccountId>"
zone_id = "<prodCloudflareZoneId>"
name = "<worker_name>"
route = "<worker_route>"
kv-namespaces = [
  { binding = "workerStore", id = "<worker_id>" }
]

[env.staging]
account_id = "<cloudflareAccountId>"
zone_id = "<stagingCloudflareZoneId>"
name = "<worker_name>"
route = "<worker_route>"
kv-namespaces = [
  { binding = "workerStore", id = "<worker_id>" }
]

2 Likes