DEV Community

Cover image for AWS Under the Hood - Day 11 - Monitor Your S3 Bucket: Get Notified on every S3 event
Prashant Lakhera
Prashant Lakhera

Posted on

AWS Under the Hood - Day 11 - Monitor Your S3 Bucket: Get Notified on every S3 event

This is a common requirement: You need to be notified of events such as someone deleting or uploading an object to your S3 bucket. Often, we begin writing our own Lambda functions, but AWS provides its two-managed solutions for these notifications. They are:

AWS S3 Event Notifications
AWS S3 event notifications are specifically designed to respond to changes in an S3 bucket, such as the creation, deletion, or modification of objects.

  • Use Case: S3 event notifications are best when responding to changes in an S3 bucket directly and primarily route the events to S3-related workflows (e.g., processing uploaded files and logging deletions).
  • Features:It is triggered by specific S3 bucket operations like PUT, POST, DELETE, and others.Target AWS Lambda, SNS, SQS, and other AWS services directly.Simpler to set up for specific S3 bucket events without a broader event management system.Ideal for workflows that are directly connected to object storage activities

To Configure S3 events

  • Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/.
  • In the Buckets list, choose the name of the bucket that you want to enable events for.
  • Choose Properties.
  • Navigate to the Event Notifications section and choose Create event notification.
  • In the General configuration section, specify descriptive event name for your event notification. Optionally, you can also specify a prefix and a suffix to limit the notifications to objects with keys ending in the specified characters.
  • In the Event types section, select one or more event types that you want to receive notifications for.
  • Choose Save changes, and Amazon S3 sends a test message to the event notification destination.

Reference: https://docs.aws.amazon.com/AmazonS3/latest/userguide/notification-how-to-event-types-and-destinations.html#supported-notification-event-types

AWS EventBridge for S3
EventBridge can be configured to listen to events from an S3 bucket as a part of its broader event management capabilities. When using EventBridge with S3:

  • Integration: EventBridge requires integration with S3, which is achieved by attaching a resource-based policy to the S3 bucket, which enables the bucket to send events to EventBridge.
  • Flexibility: EventBridge allows more complex routing and event filtering rules. You can filter and route S3 events based on their detailed attributes, such as object size, timestamp, and more.
  • Targets: EventBridge can route events to a wider range of AWS services than S3 event notifications. It can also trigger workflows in other AWS services directly or integrate with third-party services.
  • Setup: Setting up EventBridge to handle S3 events can involve more than direct S3 event notifications. It typically involves creating an event bus, setting up rules, and ensuring proper permissions.

Choosing Between Them

  • Using EventBridge for S3 events provides greater flexibility and a more centralized approach to managing events across multiple sources and AWS services. It's handy in complex applications where events from various services need to be orchestrated in sophisticated ways.
  • Direct S3 event notifications, meanwhile, offer a simpler and sometimes quicker way to respond to changes in S3 if your needs are relatively straightforward and limited to actions directly related to objects in your buckets.
  • Each method has its strengths, and the choice depends on your specific needs, the complexity of your environment, and how you plan to handle events across your AWS infrastructure.

Top comments (0)