Skip to main content
The Bucket component lets you add an AWS S3 Bucket to your app.

Constructor

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

Parameters

access

access
"public" | "cloudfront"
Enable public read access for all files in the bucket.
{
  access: "public"
}
If using a Router to serve files, use "cloudfront" access instead.

cors

cors
boolean | object
default:"true"
Configure CORS (Cross-origin resource sharing) settings.
{
  cors: {
    allowOrigins: ["https://example.com"],
    allowMethods: ["GET", "POST"]
  }
}
Disable CORS:
{
  cors: false
}

versioning

versioning
boolean
default:"false"
Enable versioning to store multiple versions of each object.
{
  versioning: true
}

lifecycle

lifecycle
array
Configure lifecycle rules to automatically delete or archive objects.
{
  lifecycle: [
    {
      prefix: "/tmp",
      expiresIn: "30 days"
    }
  ]
}

Properties

name

arn

domain

nodes

Methods

notify

SDK

Access bucket properties in your function code:
src/lambda.ts
import { Resource } from "sst";
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";

const client = new S3Client();
await client.send(new PutObjectCommand({
  Bucket: Resource.MyBucket.name,
  Key: "file.txt",
  Body: "Hello World"
}));

Examples

Enable public access

sst.config.ts
new sst.aws.Bucket("MyBucket", {
  access: "public"
});

Add notifications

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

bucket.notify({
  notifications: [
    {
      name: "MySubscriber",
      function: "src/subscriber.handler",
      events: ["s3:ObjectCreated:*"]
    }
  ]
});
sst.config.ts
const bucket = new sst.aws.Bucket("MyBucket");

new sst.aws.Function("MyFunction", {
  handler: "src/api.handler",
  link: [bucket]
});

Build docs developers (and LLMs) love