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

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

You can link the bucket to a worker.

sst.config.ts
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, opts: ComponentResourceOptions, name: string) => 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

Use the SDK in your runtime to interact with your infrastructure.


Bindings

When you link a bucket to a worker, you can interact with it using these Bucket methods.

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