AWS Bites Podcast

24. What's SNS and how do you use it?

Luciano and Eoin deep dive into SNS discussing what it does, how it differs from EventBridge and SQS and how you can use it to send messages to customers but also for microservices communication. In this new episode dedicated to AWS events and messaging services, we learn everything there is to know about SNS including advantages, limitations and cost. This episode complements the episode about EventBridge, giving another perspective on when to use SNS and when to pick EventBridge instead.

In this episode we mentioned the following resources:

Let's talk!

Do you agree with our opinions? Do you have interesting AWS questions you'd like us to chat about? Leave a comment on YouTube or connect with us on:

00:05:00

For instance, if you do a subscription that requires the destination to be an email or HTTP or endpoints that live in another AWS account, AWS will actually ask you to confirm that that subscription needs to be confirmed before it's actually activated. And sometimes, for instance, you can receive an email and you have to click a link on that email or there are APIs that you can use if you need to do that in an automated fashion. Then at that point, once you have a topic and a subscription, you can publish one or more messages to that topic and you can use either the publish API, which gives you one message, or the publish batch, which allows you to publish more than one message with one single request. And that's interesting. But another thing that is very interesting is that very often you need to also configure what are called access control policies, which are something very similar to IAM policies, at least they have the very similar structure. But those are basically the way you can authorize, for instance, certain users to publish to a specific topic or SNS itself to be able to deliver to a queue. So give SNS the permission to use the put message API to SQS. And you can also put different limitations in places. For instance, you could say for this particular topic, I only want subscription that deliver to HTTPS, for instance. So you can use all this feature to create restrictions on how messages are consumed, but also how messages are published to the topic. Are there other interesting details that are worth mentioning in terms of, I don't know, the user experience of creating messages and consuming them? If you remember with EventBridge, we were talking about rules and how you do pattern matching.

00:11:26

And the reason why is because in a topic, when you subscribe, you generally get all the messages in that topic, while in EventBridge, you generally provide rules that will allow you to select only messages with a particular structure that you are interested in consuming. So EventBridge is generally, you have the common bus for everything, and you just select things that you are interested in by providing a pattern. With SNS, you select the specific topic that has the information you want. You can probably achieve something similar with filtering, but we already mentioned that SNS filtering, you can only filter on metadata and not the message content. So you will need to craft that metadata in advance for the rules that you expect if you want to use filtering to select a subset of the messages in the topic. Also, another interesting thing that we mentioned in the previous episode that EventBridge gives you AWS events or even third-party integration events, like Salesforce or stuff like that, while in SNS, you don't have any of that. It's up to you to publish something into the different topics. SNS is much faster. Typically, you have a latency of 30 milliseconds compared to something that can be around 500 milliseconds for EventBridge. So definitely, this is probably the killer feature that is going to make SNS win against EventBridge in certain scenarios. Like when you really need good latency, SNS is your choice. EventBridge has many supported targets, while SNS is a little bit more limited. We'll mention some of them in a second. And the other interesting thing, this is very cool feature that I really like from EventBridge, that when you do HTTP targets, you can define a template that allows you to change the structure of how the HTTP request is going to be sent. Instead, with SNS, there is a standard format and that's it. So you'll need to build your APIs to accept that format. Instead, EventBridge is a lot more flexible in that sense. Or you'd have to put a Lambda function in between, I guess, if you need to transform it.

Help us to make this transcription better! If you find an error, please submit a PR with your corrections.