Skip to content

rso_bucket_notification (Resource)

Sends a message to a queue or a topic when objects in a bucket are created or removed, for example to process every upload.

The message has the S3 event notification shape (Records[0].eventName is ObjectCreated:Put, ObjectCreated:CompleteMultipartUpload or ObjectRemoved:Delete). Delivery is at least once, and events of different keys can arrive out of order. Objects that already exist are not announced.

Set exactly one of queue and topic. Every argument forces a new notification.

Example Usage

# Announce every new or removed object under uploads/ on a queue.
resource "rso_bucket_notification" "uploads" {
  bucket     = rso_bucket.media.name
  events     = ["CREATED", "REMOVED"]
  key_prefix = "uploads/"
  queue      = rso_queue.uploads.name
}

# Or fan the events out through a topic.
resource "rso_bucket_notification" "all" {
  bucket      = rso_bucket.media.name
  events      = ["CREATED"]
  topic       = rso_topic.events.name
  routing_key = "storage.media.created"
}

Schema

Required

  • bucket (String) Bucket name, as in rso_bucket.name.
  • events (Set of String) Which changes to announce: CREATED, REMOVED or both.

Optional

  • key_prefix (String) Only objects whose key starts with this.
  • key_suffix (String) Only objects whose key ends with this, for example .jpg.
  • queue (String) Queue that receives the messages.
  • routing_key (String) With topic: the routing key the messages are published with.
  • topic (String) Topic that receives the messages, as an alternative to queue.

Read-Only

  • id (String) Notification id.

Import

Import is supported using the following syntax:

# Import a notification as <bucket>/<id>.
terraform import rso_bucket_notification.uploads media/7c1f0a9e