Skip to content

wrangler kv:namespace create <namespace> treats <namespace> as a binding name rather than the resource name #4248

Description

@1000hz

Describe the solution

Currently, when creating a new KV namespace via Wrangler, it tries to be helpful and print out a snippet for the user to paste into their wrangler.toml file.

wrangler kv:namespace create "MY_KV"
🌀 Creating namespace with title "worker-MY_KV"
✨ Success!
Add the following to your configuration file in your kv_namespaces array:
kv_namespaces = [
  { binding = "MY_KV", id = "e29b263ab50e42ce9b637fa8370175e8" }
]

But notice that we're treating what the user expects to be their resource name as the name of the binding, with the actual name given to the resource being some decorated variation of that. As a result, we also artificially limit what a user can name their resource via this command by what constitutes a valid JS identifier (e.g. no dashes are allowed here, though KV namespaces can indeed contain dashes in their name).

We should fix this so that the resource is created with the name the user intended. We should output the resource name along with its ID. We can still output a helpful snippet for the user to paste into wrangler.toml, albeit leaving it up to them to replace the binding name with what they want.

wrangler kv:namespace create "my-kv-namespace"
🌀 Creating KV namespace...
✨ Success!
Created the following KV namespace:
    my-kv-namespace: e29b263ab50e42ce9b637fa8370175e8

To start using this resource in your worker, add an entry to `kv_namespaces` in your wrangler.toml file:

kv_namespaces = [
  { binding = "<VARIABLE_NAME>" id = "e29b263ab50e42ce9b637fa8370175e8" }
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions