Documentation Index
Fetch the complete documentation index at: https://mintlify.com/anomalyco/sst/llms.txt
Use this file to discover all available pages before exploring further.
The Bucket component lets you add an AWS S3 Bucket to your app.
Constructor
const bucket = new sst.aws.Bucket("MyBucket");
Parameters
access
Enable public read access for all files in the bucket.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:
versioning
Enable versioning to store multiple versions of each object.
lifecycle
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:
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
new sst.aws.Bucket("MyBucket", {
access: "public"
});
Add notifications
const bucket = new sst.aws.Bucket("MyBucket");
bucket.notify({
notifications: [
{
name: "MySubscriber",
function: "src/subscriber.handler",
events: ["s3:ObjectCreated:*"]
}
]
});
Link to a function
const bucket = new sst.aws.Bucket("MyBucket");
new sst.aws.Function("MyFunction", {
handler: "src/api.handler",
link: [bucket]
});