SNS and EventBridge
Overview
Amazon SNS is a pub/sub service: a publisher sends one message to a topic and SNS pushes copies to every subscriber. Amazon EventBridge is an event bus that receives events from AWS services, your apps and SaaS partners, and routes them to targets based on rules that match event content.
Picture a radio station versus a smart mail room. SNS is the radio: everyone tuned in hears the broadcast (with optional filters for the channels they care about). EventBridge is the mail room: it reads each envelope, checks routing rules and sends it to the right departments.
Both enable event-driven designs. The exam asks when to choose each, and how to combine SNS with SQS for fan-out.
Key Concepts
- SNS delivers to SQS, Lambda, HTTP/S, email, SMS, mobile push and Firehose; standard topics are at-least-once, FIFO topics preserve order (subscribers: SQS FIFO and standard).
- Fan-out: SNS topic to multiple SQS queues gives each consumer its own durable buffer and retry behaviour.
- Subscription filter policies filter by message attributes or body so subscribers only get relevant messages.
- EventBridge buses receive events from 200+ AWS services (default bus), custom apps (
PutEvents) and SaaS partners. - Rules match event patterns (JSON) and route to up to 5 targets; features include input transformers, retries, DLQ per target, archive and replay.
- EventBridge Scheduler runs one-off or recurring jobs at scale (cron/rate, time zones); Pipes connect a source to a target with filtering and enrichment.
- SNS has a lower per-message cost and very high throughput; EventBridge offers content-based routing, schema discovery and more integrations.
- Both support cross-account delivery via resource policies.
Detailed Notes
SNS fan-out with filtering
Resources:
OrdersTopic:
Type: AWS::SNS::Topic
BillingQueue:
Type: AWS::SQS::Queue
BillingSub:
Type: AWS::SNS::Subscription
Properties:
TopicArn: !Ref OrdersTopic
Protocol: sqs
Endpoint: !GetAtt BillingQueue.Arn
RawMessageDelivery: true
FilterPolicy:
orderType: [premium]
The queue needs a resource policy letting sns.amazonaws.com send messages with aws:SourceArn equal to the topic.
import boto3, json
sns = boto3.client("sns")
sns.publish(
TopicArn=TOPIC_ARN,
Message=json.dumps({"orderId": 42}),
MessageAttributes={"orderType": {"DataType": "String", "StringValue": "premium"}},
)
EventBridge rule and event
{
"source": ["com.shop.orders"],
"detail-type": ["OrderPlaced"],
"detail": { "total": [{ "numeric": [">", 100] }], "country": ["IN", "SG"] }
}
import boto3, json
events = boto3.client("events")
events.put_events(Entries=[{
"Source": "com.shop.orders",
"DetailType": "OrderPlaced",
"Detail": json.dumps({"orderId": 42, "total": 250, "country": "IN"}),
"EventBusName": "shop-bus",
}])
PutEvents can fail per entry; check FailedEntryCount and retry failed entries.
SNS vs EventBridge
| Aspect | SNS | EventBridge |
|---|---|---|
| Model | Topic pub/sub | Event bus with rules |
| Filtering | Attribute/body filter per subscription | Rich pattern matching (prefix, numeric, exists, etc.) |
| Sources | Your publishers | AWS services, SaaS, custom |
| Targets | SQS, Lambda, HTTP, email, SMS, push | 20+ AWS service targets, API destinations |
| Replay/archive | No (FIFO has replay) | Yes |
| Throughput | Very high | High, with default quotas |
| Typical use | Fan-out notifications, mobile push | Event-driven integration, SaaS, scheduling |
Reliability
- SNS retries deliveries to HTTP and Lambda according to a delivery policy; failed deliveries can go to a subscription DLQ (SQS).
- EventBridge retries targets for up to 24 hours (185 attempts by default) and supports DLQ per target.
- Both are at-least-once, so consumers need idempotency.
Scheduling
aws scheduler create-schedule --name nightly-report \
--schedule-expression "cron(0 2 * * ? *)" \
--schedule-expression-timezone "Asia/Kolkata" \
--flexible-time-window Mode=OFF \
--target '{"Arn":"arn:aws:lambda:eu-west-1:111122223333:function:Report","RoleArn":"arn:aws:iam::111122223333:role/SchedulerRole"}'
Reacting to AWS events
Common patterns: EC2 state change, CodePipeline failure, S3 object created, GuardDuty finding. Event pattern {"source":["aws.ec2"],"detail-type":["EC2 Instance State-change Notification"]} routes to Lambda or SNS.
Choosing between them
- Need to push the same message to many consumers with minimal logic -> SNS (often to SQS).
- Need routing by content or integration with AWS/SaaS events -> EventBridge.
- Need point-to-point buffering -> SQS.
EventBridge in practice
A rule matches events by an event pattern and routes them to up to five targets (Lambda, SQS, SNS, Step Functions, API destinations and more). Custom buses isolate application events, a schedule (cron or rate, or EventBridge Scheduler for one-off and flexible schedules) triggers jobs, and Pipes connect a source (SQS, Kinesis, DynamoDB Streams) to a target with optional filtering and enrichment.
{
"source": ["com.example.orders"],
"detail-type": ["OrderPlaced"],
"detail": { "total": [{ "numeric": [">", 1000] }], "country": [{ "anything-but": ["XX"] }] }
}
import json, boto3
events = boto3.client("events")
resp = events.put_events(Entries=[{
"Source": "com.example.orders", "DetailType": "OrderPlaced",
"Detail": json.dumps({"orderId": "o1", "total": 1500, "country": "IE"}),
"EventBusName": "orders-bus"}])
assert resp["FailedEntryCount"] == 0
SNS details
| Feature | Behaviour |
|---|---|
| Subscribers | SQS, Lambda, HTTP(S), email, SMS, mobile push, Firehose |
| Filter policies | Per subscription, on message attributes or body |
| Delivery retries | Per protocol policy; failed deliveries can go to a subscription DLQ |
| FIFO topics | Ordered, deduplicated delivery to SQS FIFO |
| Message size | Up to 256 KB |
Compare quickly: SNS pushes to many subscribers with simple filtering; EventBridge adds content-based routing on any JSON field, schema registry, SaaS sources, archive and replay; SQS holds work until a consumer pulls it. When EventBridge fails to deliver to a target it retries for up to 24 hours and can send the event to a DLQ.
Real World Example
An online marketplace publishes an OrderPlaced event to EventBridge. Rules route premium orders to a fraud-check Step Function, all orders to an analytics Firehose and orders to a given country to a regional fulfilment Lambda. For legacy teams that only support queues, a rule targets an SNS topic that fans out to three SQS queues with filter policies. New consumers subscribe without any change to the order service, and archive and replay let them backfill past events.
Architecture Diagram
One event is delivered to many consumers without the producer knowing them.
- 1The producer puts an event on the bus.
- 2EventBridge rules evaluate the event pattern.
- 3Matching targets, such as Step Functions or SNS, are invoked.
- 4SNS fans the message out to each subscribed queue.
Best Practices
- ✓Use SNS to SQS fan-out so each consumer has its own buffer and DLQ.
- ✓Use filter policies and event patterns instead of filtering in code.
- ✓Configure DLQs for subscriptions and rule targets.
- ✓Check FailedEntryCount on PutEvents.
- ✓Use EventBridge Scheduler instead of per-minute cron rules for per-item schedules.
Common Interview Questions
Exam Tips
DVA-C02 focus
- Fan-out to many consumers -> SNS + SQS.
- Schedule or react to AWS service events -> EventBridge.
- Rule target fails after retries -> configure a DLQ.
- Filter at subscription level -> SNS filter policy.
Finished this lesson?
0 of 46 lessons done · 0% of the course

