Hi Reader ๐๐ฝ
This is another issue that is all about messaging systems and patterns. It is the last one of this series. After that, we continue with more networking services ๐ช
This time we talk about the service Simple Notification Service or better known as SNS ๐จ
To get you excited, here is one upfront guessing question: What's the subscription limit per topic? ๐ค Scroll down to find the answer.
But now let's get into the overview of this issue:
Let's get into it! ๐
Amazon SNS is a fully managed publish & subscribe service.
The fundamentals are quite simple:
Subscribers can either be personal applications like smartphone notifications, emails, or SMS. A subscriber can also be another AWS Service.
SNS publishes messages to subscribers with a push-based model. Once a message comes in, SNS pushes out the message to its subscribers immediately.
SQS on the other hand is a poll-based mode. That means a message remains in a queue and consumers poll this message.
SNS supports a lot of different destinations to which it can deliver messages. SNS distinguishes those into two endpoint groups:
SNS works exceptionally well for the use-case of sending a message to many subscribers. This pattern is called Fan-out.
This is also the major difference to SQS, as SQS only has one consumer per message (excluding the cases where reprocessing is happening due to errors).
As with other AWS services, SNS is fully integrated with IAM. This means you can control access to your topics via topic policies.
You can also encrypt your data in SNS. You need to encrypt the message in two places, in transit and at rest.
SNS handles the whole encryption process on the server side. You can either use a key of AWS's own Key Service (KMS) or provide a custom one. This will encrypt all sensitive data in your message.
In SNS you can choose two different types of topics.
โ
Message filtering allows you to send only a subset of messages to subscribers. You can assign filter policies that check the message for certain attributes. If a message meets these policies, SNS sends it to the subscriber. This allows a flexible routing mechanism.
The filter policy can be applied both to Message Attributes and the Message Body.
In the example, we're filtering based on the message payload isBlogPost. Some of our subscribers are ignoring messages that have this field set to true, while all of them are listening to messages that have the field set to false.
For each delivery protocol, SNS defines a delivery policy. With this protocol, you can define how retries are happening. Retries will only happen on server-side errors.
Compared to SQS, SNS is not aware of errors happening inside of your Lambda function.
SNS only cares about sending out your messages. That means once your message is out it is successfully processed by SNS.
If your Lambda function fails to work on the message the delivery protocol will not be aware of that. SNS calls your Lambda function asynchronously. We highlight this because this is very often misunderstood.
A common server-side error is a missing IAM policy. If your topic isnโt allowed to call a Lambda function a server-side error will occur.
Another error would be if the Lambda API is down but this doesnโt happen very often (fortunately).
With the delivery protocol, you can then define retries.
SNS is a serverless service. You donโt have any fees if you donโt use it. The charges are completely usage-based.
Free Tier: The free tier covers 1 million requests, 100k notifications, 100 SMS, and 1000 notifications via email every month.
SNS is an amazing service to build high-throughput, customer-facing applications. The ability to use application and personal endpoints are amazing in SNS.
That's it for today. We hope you've enjoyed this issue!
See you in two weeks!
Sandro & Tobi ๐
P.S.: there can be 12,500,00 subscribers per topic! ๐ฅ
โ
This week, we want to give a huge shout-out to Allen Helton. Watching Allen's story unfoldโfrom becoming an AWS Community Builder and AWS Hero to joining the amazing Momento teamโhas been amazing.
Allen shares a lot of content through his newsletter, blog, and podcast. He is always happy to assist you if you need help with anything cloud-related. Thanks, Allen!
Still hungry for AWS content? Have a look at our blog! ๐ โ
Join our community of over 8,800 readers delving into AWS. We highlight real-world best practices through easy-to-understand visualizations and one-pagers. Expect a fresh newsletter edition every two weeks.
โ Reading time: 13 minutes ๐ Main Learning: How to Run Apps on Fargate via ECS ๐พ GitHub Repository โ๏ธ Read the Full Post Online ๐ Hey Reader ๐๐ฝ When building applications on AWS, we need to run our code somewhere: a computation service. There are a lot of well-known and mature computation services on AWS. Youโll often find Lambda as the primary choice, as itโs where you donโt need to manage any infrastructure. You only need to bring your code - itโs Serverless โก๏ธ. However, more options can be...
โ Reading time: 10 minutes ๐ Main Learning: Running Postgres on Aurora DSQL with Drizzle ๐พ GitHub Repository โ๏ธ Read the Full Post Online ๐ Hey Reader ๐๐ฝ With re:Invent 2024, AWS finally came up with an answer to what many people (including us) asked for years: "What if there were something like DynamoDB but for SQL?" With Amazon Aurora DSQL, this is finally possible. Itโs not just a โscales-to-zeroโ solution like Aurora Serverless V2. It is a true distributed, serverless, pay-per-use...
โ Reading time: 12 minutes ๐ Main Learning: CloudWatch Launches re:invent 2024 โ๏ธ Read the Full Post Online ๐ Hey Reader ๐๐ฝ re:invent happened already two weeks ago and there were some amazing launches ๐ CloudWatch got a lot of love at that re:invent. This is why we are showing you our top CloudWatch launches for this year. We've worked through all of them, tried to get them working with our example application of the CloudWatch Book, and are now busy updating the book โ๐ฝ. Let's dive into...