Skip to content

Bucket

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

The Bucket component lets you add a Cloudflare R2 Bucket to your app.

Minimal example

const bucket = new sst.cloudflare.Bucket("MyBucket");

You can link the bucket to a worker.

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

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

index.ts
import { Resource } from "sst";
await Resource.MyBucket.list();

Constructor

new Bucket(name, args?, opts?)

Parameters

BucketArgs

transform?

Type Object

Transform how this component creates its underlying resources.

transform.bucket?

Type R2BucketArgs | (args: R2BucketArgs => void)

Transform the R2 Bucket resource.

Properties

name

Type Output<string>

The generated name of the R2 Bucket.

nodes

Type Object

The underlying resources this component creates.

nodes.bucket

Type R2Bucket

The Cloudflare R2 Bucket.

SDK

The following are accessible through the SDK at runtime.

Bindings

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

index.ts
import { Resource } from "sst";
await Resource.MyBucket.list();