Skip to content

BucketNotification

Reference doc for the `sst.aws.BucketNotification` component.

The BucketNotification component is internally used by the Bucket component to add bucket notifications to AWS S3 Bucket.

You’ll find this component returned by the notify method of the Bucket component.


Constructor

new BucketNotification(name, args, opts?)

Parameters

Properties

nodes

Type Object

The underlying resources this component creates.

nodes.notification

Type BucketNotification

The notification resource that’s created.

nodes.functions

Type Output<Function[]>

The functions that will be notified.

Args

bucket

Type Input<Object>

The bucket to use.

bucket.arn

Type Input<string>

The ARN of the bucket.

bucket.name

Type Input<string>

The name of the bucket.

notifications

Type Input<Input<Object>[]>

A list of subscribers that’ll be notified when events happen in the bucket.

notifications[].events?

Type Input<Input<s3:ObjectCreated:* | s3:ObjectCreated:Put | s3:ObjectCreated:Post | s3:ObjectCreated:Copy | s3:ObjectCreated:CompleteMultipartUpload | s3:ObjectRemoved:* | s3:ObjectRemoved:Delete | s3:ObjectRemoved:DeleteMarkerCreated | s3:ObjectRestore:* | s3:ObjectRestore:Post | s3:ObjectRestore:Completed | s3:ObjectRestore:Delete | s3:ReducedRedundancyLostObject | s3:Replication:* | s3:Replication:OperationFailedReplication | s3:Replication:OperationMissedThreshold | s3:Replication:OperationReplicatedAfterThreshold | s3:Replication:OperationNotTracked | s3:LifecycleExpiration:* | s3:LifecycleExpiration:Delete | s3:LifecycleExpiration:DeleteMarkerCreated | s3:LifecycleTransition | s3:IntelligentTiering | s3:ObjectTagging:* | s3:ObjectTagging:Put | s3:ObjectTagging:Delete | s3:ObjectAcl:Put>[]>

Default All S3 events

A list of S3 event types that’ll trigger the notification.

{
events: ["s3:ObjectCreated:*", "s3:ObjectRemoved:*"]
}

notifications[].filterPrefix?

Type Input<string>

An S3 object key prefix that will trigger the notification.

To filter for all the objects in the images/ folder.

{
filterPrefix: "images/"
}

notifications[].filterSuffix?

Type Input<string>

An S3 object key suffix that will trigger the notification.

To filter for all the objects with the .jpg suffix.

{
filterSuffix: ".jpg"
}

notifications[].function?

Type Input<string | FunctionArgs | “arn:aws:lambda:${string}”>

The function that’ll be notified.

sst.config.ts
{
name: "MySubscriber",
function: "src/subscriber.handler",
}

Customize the subscriber function. The link ensures the subscriber can access the bucket.

sst.config.ts
{
name: "MySubscriber",
function: {
handler: "src/subscriber.handler",
timeout: "60 seconds",
link: [bucket]
}
}

Or pass in the ARN of an existing Lambda function.

sst.config.ts
{
name: "MySubscriber",
function: "arn:aws:lambda:us-east-1:123456789012:function:my-function",
}

notifications[].name

Type Input<string>

The name of the subscriber.

notifications[].queue?

Type Input<string | Queue>

The queue that’ll be notified.

For example, let’s say you have a queue.

sst.config.ts
const myQueue = new sst.aws.Queue("MyQueue");

You can subscribe to this bucket with it.

sst.config.ts
{
name: "MySubscriber",
queue: myQueue,
}

Or pass in the ARN of an existing SQS queue.

sst.config.ts
{
name: "MySubscriber",
queue: "arn:aws:sqs:us-east-1:123456789012:my-queue",
}

notifications[].topic?

Type Input<string | SnsTopic>

The topic that’ll be notified.

For example, let’s say you have a topic.

sst.config.ts
const myTopic = new sst.aws.SnsTopic("MyTopic");

You can subscribe to this bucket with it.

sst.config.ts
{
name: "MySubscriber",
topic: myTopic,
}

Or pass in the ARN of an existing SNS topic.

sst.config.ts
{
name: "MySubscriber",
topic: "arn:aws:sns:us-east-1:123456789012:my-topic",
}

transform?

Type Object

Transform how this notification creates its underlying resources.

transform.notification?

Type BucketNotificationArgs | (args: BucketNotificationArgs, opts: ComponentResourceOptions, name: string) => void

Transform the S3 Bucket Notification resource.