Skip to Content

Event notifications

S3 event notifications to SNS, SQS and Lambda, the resource policies they need, and sending S3 events to Amazon EventBridge.

What it is

Things happen to objects in a bucket: they're created, deleted, restored from Glacier, replicated. S3 event notifications let other services react to those events automatically, instead of checking the bucket over and over.

The classic use case: generate a thumbnail every time an image is uploaded.

How it works

S3 event notifications: when a matching event happens, such as a new .jpg object, the bucket sends it to Amazon SNS, Amazon SQS or AWS Lambda; it can also send every event to Amazon EventBridge, whose rules route it to many targets S3 event notifications: when a matching event happens, such as a new .jpg object, the bucket sends it to Amazon SNS, Amazon SQS or AWS Lambda; it can also send every event to Amazon EventBridge, whose rules route it to many targets

The bucket tells other services when something happens.
  1. An event notification is added to the bucket, choosing:
    • the event types, such as s3:ObjectCreated:*, s3:ObjectRemoved:*, s3:ObjectRestore:* or s3:Replication:*;
    • an optional filter on the object name, such as prefix uploads/ and suffix .jpg;
    • a destination: an SNS topic, an SQS queue or a Lambda function.
  2. When a matching event happens, S3 sends a JSON message describing it (bucket, key, size, event time) to the destination.
  3. A bucket can have as many event notifications as needed.

Notifications are typically delivered in seconds, but can sometimes take a minute or longer.

SQS FIFO queues aren't supported as a direct destination (use EventBridge for that). SNS and SQS are covered in the Application Integration group, Lambda in the Serverless group.

Permissions: resource policies, not IAM roles

S3 doesn't use an IAM role to deliver notifications. Instead, each destination needs a resource (access) policy that allows the S3 service to use it:

  • SNS topic: an access policy allowing s3.amazonaws.com to SNS:Publish;
  • SQS queue: an access policy allowing s3.amazonaws.com to SQS:SendMessage;
  • Lambda function: a resource-based policy allowing s3.amazonaws.com to lambda:InvokeFunction.

Each usually has a condition that the source is the bucket (aws:SourceArn). The console adds the Lambda permission automatically.

S3 events with Amazon EventBridge

Amazon EventBridge can also be turned on for the bucket. Then:

  • All events go to EventBridge; event types aren't picked on the bucket.
  • Advanced filtering with JSON rules: on metadata, object size, name and more.
  • Many destinations: EventBridge rules can send events to dozens of AWS services, such as Step Functions, Kinesis Data Streams and Firehose.
  • EventBridge features: archive and replay events, and reliable delivery.

See Amazon EventBridge.

Real-world examples

  • A photo app triggers a Lambda function on every new .jpg in uploads/, which writes a thumbnail to thumbnails/.
  • A media company sends new-video events to an SQS queue, and a fleet of EC2 workers transcodes them at its own pace.
  • A compliance team sends every object deletion to EventBridge, which notifies security and records the event.

Exam tips

  • "Run code when an object is uploaded", "thumbnail on upload" → S3 event notification to Lambda.
  • "Queue uploaded files for processing" → event notification to SQS.
  • "Notify several subscribers of a new object" → SNS (fan-out).
  • "Advanced filtering, many targets, archive and replay of S3 events" → EventBridge.
  • "S3 can't send to the queue" → the queue's access policy must allow s3.amazonaws.com.

Common traps

  • "Give S3 an IAM role to send notifications." Destinations need resource policies instead.
  • "Event notifications are instant and exactly once." Usually seconds, sometimes a minute or more.
  • "Send S3 events straight to an SQS FIFO queue." Not supported directly; use EventBridge.
  • "A Lambda function triggered by uploads writes back to the same prefix." That triggers itself in a loop; write to a different prefix or bucket.

Hands-on lab: events into an SQS queue

Goal: send upload events from a bucket to an SQS queue and read one.

Costs money

A handful of SQS messages and S3 requests cost less than a cent. Any Region works.

Create a queue that S3 can write to

SQS → Create queue, Standard, name saa-s3-events. Under Access policy → Advanced, add a statement allowing "Service": "s3.amazonaws.com" to "SQS:SendMessage" on the queue ARN, with condition "ArnLike": {"aws:SourceArn": "arn:aws:s3:::<your-bucket>"}. Create.

Add the notification

In your lab bucket, Properties → Event notifications → Create event notification. Name uploads, prefix uploads/, event type All object create events, destination SQS queue saa-s3-events. Save. (If S3 reports it can't validate the destination, the access policy is wrong.)

Upload and read the message

Upload a file into uploads/. In SQS, open the queue → Send and receive messages → Poll for messages. Open the newest message: a JSON event with eventName: ObjectCreated:Put and your object's key. (The first message may be a s3:TestEvent.)

Expected result: every upload under uploads/ produces a message in the queue.

Clean up: delete the event notification, the saa-s3-events queue and the test object.

AWS documentation

On this page

Open notes

Spotted a mistake?

These notes are open source. Suggest a fix, or star the repo if they helped you.

Suggest an edit

For AI agents: llms.txt · llms-full.txt