Sunday, July 20, 2025

Amazon Simple Notification Service (SNS) | Overview & Hands-On.

Amazon Simple Notification Service (SNS) - Overview & Hands-On.

Scope:

  • Intro,
  • Key Use Cases,
  • KeyTerminology,
  • Architecture,
  • Supported Protocols for Subscribers (Integration),
  • How SNS Works (flow diagram),
  • Security & Permissions,
  • Features at a Glance,
  • SNS vs. SQS,
  • Sample of Using SNS + SQS Fan-Out,
  • Sample Asynchronous (auto) messaging Flow in AWS
  • Sample synchronous (human induced trigger)  Messaging flow in AWS
  • Benefits of Asynchronous Design,
  • Asynchronous Tools in AWS,
  • Services that can send data directly (Aynchronously) to SNS for notifications,
  • Project: Hands-On.

Intro:

  • Amazon SNS is a fully managed pub/sub (publish/subscribe) messaging service used to send messages from producers (publishers) to multiple consumers (subscribers) asynchronously.

Key Use Cases

Use Case

Description

Application decoupling

Producers publish messages; subscribers process independently.

Fan-out pattern

One message sent to many endpoints (e.g., Lambda, SQS, HTTP).

Mobile push notifications

Sends notifications to iOS, Android, Fire OS devices.

Email/SMS alerts

Sends alerts to users or admins.

Workflow triggers

Event-based architecture (e.g., image upload → start processing pipeline).

KeyTerminology

  • Topic: A logical access point where publishers send messages.
  • Publisher: The sender (e.g., application, Lambda, script).
  • Subscriber: Endpoints that receive messages from a topic.
  • Subscription: A configuration that connects a topic to a subscriber.
Architecture

 Supported Protocols for Subscribers (Integration)

Protocol

Example

SQS

Queue receives message. Good for decoupling or buffering.

Lambda

Message triggers Lambda function.

HTTP/S

POSTs message to a webhook or REST endpoint.

Email

Sends text message to an email address.

SMS

Sends text message to a mobile phone.

Application

Sends push notifications to mobile devices.

 How SNS Works (flow diagram)


NB
  • One message is sent to the SNS topic.
  • All subscribers receive a copy of the message simultaneously.

 Security & Permissions

  • IAM policies: Control who can publish or subscribe.
  • Topic access policies: Restrict which AWS accounts/services can interact.
  • Encryption: Support for server-side encryption using AWS KMS.
  • Message filtering: Subscribers can filter messages by attributes (e.g., only receive certain event types).

 Features at a Glance

Feature

Description

Message fan-out

Send a message to many endpoints.

Message filtering

Subscribers get only messages they care about.

Durability

High availability and redundancy.

Push-based

Instantly delivers messages — no polling.

Global reach

SMS/email/mobile push globally.

 SNS vs. SQS

Feature

SNS

SQS

Model

Pub/Sub (Push)

Message Queue (Pull)

Delivery

Pushes to multiple subscribers

Consumers poll for messages

Use Case

Notifications, fan-out, alerts

Decoupling, buffering, retries

Ordering

No ordering guarantees

FIFO queues available

Retry Logic

Retry per subscriber protocol

Built-in redrive policy

Sample of Using SNS + SQS Fan-Out

  1. Create an SNS topic.
  2. Create two SQS queues.
  3. Subscribe both SQS queues to the SNS topic.
  4. Publish a message to the topic both queues receive a copy.

twtech Insights:

What "Asynchronously" Means in AWS Context.

  • Asynchronously means that tasks or communication between services happen independently ( auto) and non-blocking.
  • Also the sender doesn’t wait for the receiver to finish processing.

Sample in AWS: SNS + SQS = Asynchronous Flow

  • Let’s say twtech has a web application that processes image uploads.

Sample synchronous (human-induced-trigger) Messaging flow,



NB:

  •        twtech-web-app publishes a message to SNS.
  •         SNS asynchronously delivers the message to an SQS queue.
  •         Worker processes pull from the queue and process the image independently.
  •        twtech-web-app may immediately have return a response (feedback) like “Upload received.

 Benefits of Asynchronous Design

Benefit

Why It Matters

Low latency

Sender doesn't wait — better user experience.

Resilience

Systems continue operating even if downstream is slow/down.

Scalability

Easier to scale consumers based on message volume.

Decoupling

Components evolve independently — no direct dependencies.

Retry logic

Messages can be retried without re-sending from sender.

  Asynchronous Tools in AWS

Service

Role in Asynchronous Communication

Amazon SQS

Buffer messages for consumers to process later.

Amazon SNS

Publish messages to many consumers instantly.

AWS Lambda

Responds to events without needing direct integration.

EventBridge

Event bus for routing events across AWS services.

twtech may send a single massages to many recievers.

NB:

  • twtech may have up to 12,500,000 subscriptions per topic.
  • twtech may have up to 100,000 topics.
  • SNS integrates with a lot of AWS services. 
The following services can send data directly (Aynchronously) to SNS for notifications.

  •         CloudWatch Alarms,
  •        S3 Bucket (Events),
  •        Auto Scaling Group (Notifications),
  •        CloudFormation (State Changes),
  •        AWS Budgets,
  •        Lambda,
  •        AWS DMS (New Replic),
  •        DynamoDB 
  •        RDS Events.


Project: Hands-on

  • How twtech creates and use SNS for Messaging in its environment.
  • Search for the aws service: SNS (Simple Notification Service)


  • Add a topic name and create an SNS topic: twtech-SNS-Topic

  • Select Type: Standard
  • Topic type cannot be modified after topic is created.

Encryption - optional
  • Amazon SNS provides in-transit encryption by default.
  • Enabling server-side encryption adds at-rest encryption to your topic.

Access policy optional
  • This policy defines who can access twtech topic. 
NB:
  • By default, only the topic owner can publish or subscribe to the topic.

Data protection policy optional
  • This policy defines which sensitive data to monitor and to prevent from being exchanged via your topic.

Delivery policy (HTTP/S) - optional
  • The policy defines how Amazon SNS retries failed deliveries to HTTP/S endpoints. 
  • To modify the default settings, expand this section.

Delivery status logging optional
  • These settings configure the logging of message delivery status to CloudWatch Logs.

Tags optional
  • A tag is a metadata label that twtech can assign to an Amazon SNS topic.
  • Each tag consists of a key and an optional value. 
  • twtech can use tags to search and filter your topics and track its costs. 

Active tracing optional
  • Use AWS X-Ray active tracing for this topic to view its traces and service map in Amazon CloudWatch. 
  • Additional costs apply.

  • Create sns topic: twtech-SNS-Topic

  •  twtech creates its subscriptions:

To Create subscription:

  • twtech Remember to select the appropriate protocol (if pattern used is): Email
  •  And
  • Confirm subscription after creating from email used: twtech671@gmail.com 

Subscription filter policy optional
  • This policy filters the messages that a subscriber receives.

  • Redrive policy (dead-letter queue) - optional
  • Send undeliverable messages to a dead-letter queue.
  • Redrive policy (dead-letter queue)


  • Create subscription:

From:

To:

  • click on the link to confirm: twtech Confirms subscription.



  • Go back to SNS topic created and refresh page: To see status

From:

To: 

  • The refreshed page indicates new status as: Confirmed

  • twtech publishes messages on the  SNS Topic: twtech-SNS-Topic


  • Message details

Message body

Message attributes
  • Message attributes let twtech to provide structured metadata items (such as timestamps, geospatial data, signatures, and identifiers) for the message.

  • Publish the message:

  • Verify content of message form SNS created

  • twtech creates a subscription with another pattern (protocol): Amazon SQS pattern

  • Select pattern of choice (protocol): Amazon SQS pattern
Setup endpoint: 
  • Only Amazon SQS standard queues will be listed and can receive notifications from an Amazon SNS standard topic.





No comments:

Post a Comment

Amazon EventBridge | Overview.

Amazon EventBridge - Overview. Scope: Intro, Core Concepts, Key Benefits, Link to official documentation, Insights. Intro: Amazon EventBridg...