Bucket
The Bucket
component lets you add a Cloudflare R2 Bucket to
your app.
Minimal example
const bucket = new sst.cloudflare.Bucket("MyBucket");
Link to a worker
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.
import { Resource } from "sst";
await Resource.MyBucket.list();
Constructor
new Bucket(name, args?, opts?)
Parameters
-
name
string
-
args?
BucketArgs
-
opts?
ComponentResourceOptions
BucketArgs
transform?
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
nodes.bucket
Type R2Bucket
The Cloudflare R2 Bucket.
SDK
Use the SDK in your runtime to interact with your infrastructure.
Links
This is accessible through the Resource
object in the SDK.
-
name
string
The generated name of the R2 Bucket.
Bindings
When you link a bucket to a worker, you can interact with it using these Bucket methods.
import { Resource } from "sst";
await Resource.MyBucket.list();