KV Bindings Command


I am trying to properly configure the Cloudflare AMP Optimizer through Wrangler CLI and there seems to be some confusion on my end with the KV Bindings.

I need to create three environments - env.prod, env.beta, and env.dev. When I use the command wrangler kv:namespace create "prod", the namespace, prod, is also the binding. For example:

vars = { MODE = "prod" }
kv_namespaces = [
  { binding = "prod", id = "MY_ID", preview_id= "MY_PREVIEW_ID" },

I need the binding for all three environments to be KV and place all of them in my wrangler.toml file.

What is the command for creating a binding? I cannot seem to find it anywhere. Is it something I just replace the created namespace name (beta, prod, dev) with KV and wrangler publish will publish
it just fine or do I need some command to bind it?

To create a KV Namespace, environment, and binding all in one would I need to input the wrangler kv:namespace create "beta" --env=beta --binding "KV" command and do this for all three environments? Then, to create the preview ID, I would do that same exact command for all three environments but put in --preview at the end?

Any help would be greatly appreciated! I am having a lot of " Script Threw Exception" and “Client Disconnected” errors with the worker and the KV cache is not defined:
cache not defined

The ampproject team cannot replicate my issue so I am assuming it has something to do with me not setting the KV Namespaces correctly.

I actually figured it out and in case anyone needs the answer to it here you go, wrangler kv:namespace create "KV" --env=prod and to get the preview wrangler kv:namespace create "KV" --env=prod --preview.

You can check out the commands here - https://developers.cloudflare.com/workers/cli-wrangler/commands#create. The KV is still not defined, however.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.