Lesson 1 of 3 Event-Driven Automation

Automating File Processing with S3 Event Notifications

This lesson explains how Amazon S3 notifies other services when objects change, which makes it the starting point for many file-processing and housekeeping automations named in the exam guide.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose event types and destinations.
  • Send S3 events to EventBridge.
  • Design consumers for at-least-once delivery.
  • Buffer bursts of uploads through a queue.

Event types and destinations

S3 Event Notifications are configured on a bucket for event types such as s3:ObjectCreated:* (Put, Post, Copy, CompleteMultipartUpload), s3:ObjectRemoved:* (Delete, DeleteMarkerCreated), s3:ObjectRestore:*, s3:Replication:*, s3:LifecycleTransition, s3:LifecycleExpiration:*, s3:IntelligentTiering and s3:ObjectTagging:*. Notifications can be filtered by key prefix and suffix and sent to a Lambda function, an SQS queue (standard only) or an SNS topic. Each destination's resource-based policy must allow s3.amazonaws.com with the bucket as aws:SourceArn, and the bucket's account as aws:SourceAccount. Two configurations with overlapping prefixes and the same event type are not allowed.

Troubleshooting scenario

Notification configuration

Exam skills 3.2.2

Fix problems with S3 Event Notifications.

Log in to try this activity Interactive activities are free with an account.

Sending S3 events to EventBridge

Turning on Amazon EventBridge notifications for a bucket sends all its events to the default event bus, in addition to any direct notifications. EventBridge adds richer filtering (on object size, key patterns with wildcards, requester and more), up to five targets per rule, many target types (Step Functions, Systems Manager, other accounts), archive and replay, and the ability to add consumers without changing the bucket configuration. Direct notifications have lower latency and no EventBridge charge. The following table compares the options.

Direct Event Notifications
DestinationsLambda, SQS, SNS
FilteringPrefix and suffix
Multiple consumersSeparate non-overlapping configurations or SNS fan-out
ReplayNo
EventBridge
DestinationsAny EventBridge target
FilteringAny field, including size, wildcards and metadata
Multiple consumersMultiple rules
ReplayArchive and replay

The following diagram compares the two ways to deliver S3 events.

Direct S3 event notifications compared with EventBridge. Direct notifications go to SNS, SQS or Lambda with lower latency and no EventBridge charge. With EventBridge notifications turned on, every event goes to the default bus, where rules filter on size, key patterns or requester, reach many target types and add consumers without changing the bucket.
Both can be used on one bucket; turning on EventBridge does not remove direct notifications.

Delivery behaviour

Notifications are delivered at least once, usually within seconds, and can occasionally be duplicated or arrive out of order, so consumers must be idempotent and use the sequencer value to order events for the same key. A common mistake is a Lambda function that writes its output back to the same bucket and prefix that triggers it, causing a recursive loop; use separate buckets or prefixes. Lambda's recursive loop detection stops some loops, but the design should prevent them.

True or false

Event delivery

Exam skills 3.2.2

Check how S3 delivers event notifications.

Log in to try this activity Interactive activities are free with an account.
Worked example

Processing uploads reliably

Partners upload CSV files to s3://acme-ingest/incoming/. Each file must be validated and loaded, and bursts of thousands of files must not overwhelm the database. The operator configures an Event Notification for s3:ObjectCreated:* with prefix incoming/ and suffix .csv to an SQS queue, whose access policy allows the bucket. A Lambda function consumes the queue with maximum concurrency 10, writes results to processed/ (not matched by the filter) and moves failed files after five attempts to a DLQ.

aws s3api put-bucket-notification-configuration --bucket acme-ingest --notification-configuration '{
  "QueueConfigurations": [{
    "QueueArn": "arn:aws:sqs:eu-west-1:111122223333:ingest-queue",
    "Events": ["s3:ObjectCreated:*"],
    "Filter": {"Key": {"FilterRules": [{"Name": "prefix", "Value": "incoming/"}, {"Name": "suffix", "Value": ".csv"}]}}
  }]}'
Check yourself

Which SQS queue type can be an S3 Event Notifications destination?

Show answer

Standard queues only.

Exam Tips

Remember for the exam

  • S3 Event Notifications go to Lambda, SQS (standard) or SNS, filtered by prefix and suffix.
  • Destination policies must allow s3.amazonaws.com with the bucket as source.
  • Enable EventBridge on the bucket for richer filtering and more targets.
  • Notifications are at-least-once; make consumers idempotent.
  • Avoid writing output to the triggering prefix to prevent loops.