We have the answers to your questions! - Don't miss our next open house about the data universe!

Amazon SNS: The messaging service connected to AWS

Amazon SNS: The messaging service connected to AWS

Amazon SNS is a service for sending push notifications from an application to the end user or other programs.

It’s a comprehensive messaging service that enables communication between applications (Aapplication To Aapplication – A2A) or persons (Aapplication To Person – A2B). It allows you to create topics (i.e. subjects) that will be the logical access and communication channel.

SNS uses the pub/sub paradigm (publish / subscribe) for message delivery. This principle establishes that publishers (publishers) send messages via common communication channels called “topic” (topic), while subscribers (subscribers) automatically receive messages corresponding to the topics for which they are subscribed.

We can visualize the topics as a virtual “mailbox” that allows individual subscribers to retrieve messages without having to communicate directly with the editors. In this way, each subscriber can specify the types of messages they wish to receive, via their various subscriptions.

Source : aws.amazon.com

Definition of important terminology

It’s important to understand certain terms related to messaging services before proceeding. The table below will help you understand these key terms:

Term Description
Publisher
Image
  • The publisher is the entity responsible for sending messages on various topics and endpoints. We can think of a publisher as a person who sends messages to a mailbox.
    • Endpoints can be emails, SMS, HTTP, mobile applications, or other Amazon services (such as Lambda or SQS).
Subscriber
Image
  • The subscriber is the entity that receives published messages on a topic. We can think of the subscriber as a person who retrieves their mail from their mailbox.
    • Subscribers subscribe to a topic in order to receive messages.
    • By default, SNS offers 10 million subscriptions per topic.
Topic
Image
  • The topic is the communication channel that allows publishers to publish their messages and subscribers to receive them. We could imagine this as a shared mailbox among several people, where each person can receive letters addressed to them.
    • By default, SNS offers 100,000 topics per account.
    • Except for SMS messages, Amazon SNS messages can contain a maximum of 256 KB of text data, including XML, JSON, or plain text format.

The diagram below perfectly illustrates the elements provided above:

Source : aws.amazon.com

What are the features of AWS SNS?

Here are some of the key features of AWS SNS:

  • Scaling: the service automatically adapts to growing message volume requirements.
  • Message encryption: message protection is a priority SNS protects all messages according to encryption models. They are automatically decrypted once transmitted to the recipient’s endpoint.
  • Message filtering: the subscriber can change the filtering policy to receive only relevant notifications.
  • Replication: when a message is sent to a topic, it is replicated on several endpoints.
  • Mobile notification: actions from the application (initiated by your users) or from cloud-based business logic can be triggered
  • Email: Amazon SNS can send mail messages (SMTP)

Comparison between SNS and SQS

These are two messaging services offered by Amazon Web Services. The table below will help you understand the differences:

Feature Amazon SNS
Image
Amazon SQS
Image
Model Pub / Sub Queue
Primary Use Sending messages and notifications to multiple recipients Queue management for message delivery
Distribution All subscribers receive messages Messages are consumed by one consumer at a time
Communication Protocols HTTP, HTTPS, email, SMS, mobile, push, etc. Amazon SQS, HTTP, HTTPS
Message Format JSON, XML, plain text, etc. JSON, XML, plain text, etc.
Message Processing No built-in processing, but can be coupled with Amazon AWS Lambda Built-in processing via customizable processing workers
Capacity Management Dynamically adjustable Managed by the number of workers and the number of queues

In short, Amazon SNS is designed to send messages to multiple recipients via a pub/sub messaging model, while Amazon SQS is designed to manage message queues, with a FIFO (first-in, first-out) messaging model.

They can be used together to create a complex, highly scalable messaging architecture.

As we have just seen, SNS enables a message to be published to different supported endpoints. When an SQS queue subscribes to an SNS topic, every message sent by that SNS topic joins the queue, along with the message body and its various attributes.

The message is then almost guaranteed to be correctly distributed. “Almost”, because the SQS queue may be unavailable. In this case, Amazon SNS will make new attempts (exactly 100,010 attempts over 23 days) before the message is deleted.

If your queue is unavailable for such a long time, you most likely have a problem with your messaging infrastructure.

For more information on Amazon SQS, read our article on the subject.

How can I integrate AWS SNS?

As you probably know, one of the great strengths of Amazon AWS is the possible integration and joint operation between its various services. SNS is no exception to this rule, and can be easily integrated with different AWS services to create a complete system. Here are a few examples of possible integrations.

Amazon SNS messages can be used as triggers for AWS Lambda functions that perform various operations.

As we’ve just discussed, Amazon SNS and SQS are often used together, one for publishing messages, the other for queuing them.

If an EC2 instance, database or other resource fails, Amazon SNS can be used to alert system administrators via Cloudwatch.

Amazon SNS can publish notifications of events related to the infrastructure (AWS Elastic Beanstalk service, for example).

Your users using your S3 resources can be notified of new events (uploading or modifying information in an S3 bucket, for example).

Conclusion

AWS SNS is a powerful and versatile messaging tool that enables messages to be sent to multiple endpoints (such as email, SMS, SQS queues, mobile applications, etc.). Amazon SNS can also be integrated with other AWS services to create resilient, scalable communication architectures.

 

💡Related articles:

AWS Elastic Load Balancer: The solution that distributes network traffic
Jam AWS: The playful Amazon learning platform
AWS Lambda: Introduction to the Serverless Function
AWS Certification: What is it and how do I get it?
AWS SageMaker: A guide for using the platform
5 AWS launches and announcements making developers’ life easy in 2022

Now that you know everything there is to know about Amazon SNS, you can start learning. To do so, take a look at the DataScientest training course dedicated to Amazon Web Service.

You are not available?

Leave us your e-mail, so that we can send you your new articles when they are published!
icon newsletter

DataNews

Get monthly insider insights from experts directly in your mailbox