Skip to content

Kv

Reference doc for the `sst.cloudflare.Kv` component.

The Kv component lets you add a Cloudflare KV storage namespace to your app.

Minimal example

const storage = new sst.cloudflare.Kv("MyStorage");

You can link KV to a worker.

new sst.cloudflare.Worker("MyWorker", {
handler: "./index.ts",
link: [storage],
url: true
});

Once linked, you can use the SDK to interact with the bucket.

index.ts
import { Resource } from "sst";
await Resource.MyStorage.get("someKey");

Constructor

new Kv(name, args?, opts?)

Parameters

KvArgs

transform?

Type Object

Transform how this component creates its underlying resources.

transform.namespace?

Type WorkersKvNamespaceArgs | (args: WorkersKvNamespaceArgs => void)

Transform the R2 KV namespace resource.

Properties

id

Type Output<string>

The generated id of the KV namespace.

nodes

Type Object

The underlying resources this component creates.

nodes.namespace

Type WorkersKvNamespace

The Cloudflare KV namespace.

SDK

The following are accessible through the SDK at runtime.

Bindings

when you link a KV storage, the storage will be available to the worker and you can interact with it using the API methods documented here.

index.ts
import { Resource } from "sst";
await Resource.MyStorage.get("someKey");