/ AWS

AWS SNS

Here is what I am learning about AWS SNS (Simple Notification Service), using my Udemy course as a jumping off point.

I have already seen SNS to a small degree at work. I was tasked with creating alarms that would send notifications to our Slack channel if there were any errors in one of our services.

You create SNS “topics” which store information about where notifications should be sent to. Other services “subscribe” to your SNS topics, so when triggered, a notification is sent to wherever you have indicated during set-up. In the case above, without going into too much extra detail, I created an SNS topic, which my alarm is subscribed to. When the alarm is triggered, the SNS topic sends information to our Slack channel.

Let’s take a more detailed look at SNS. These are notes I have taken while going through the SNS section of my course.

More detail

You can use SNS to send messages to many different subscribers. One service sends a message to your SNS topic, which sends the message to all of the subscribers. This is an example of Pub/Sub or publish/subscribe pattern.

For security, set IAM permissions and SNS Access Policies.

If you set an email as a subscription, you will need to confirm the email address. You will get an email from AWS with a link to confirm subscription.

If you want to test if your topic and subscriptions are working properly, go to the SNS console, click on your topic, and click the button “publish message”. Your subscribers should now receive a message.

My issues setting it up with Slack

I should note, though, that when I set up our Slack channel with SNS (with AWS Chatbot as a subscriber), no messages were received in Slack when I tried “publish message”. I spent a lot of time going through my IAM policies, assuming it was a permissions error, but there was actually a better way to test if Chatbot was working. You had to try it out by creating an alarm in Cloudwatch and connecting it to the SNS topic. Here is the article that outlines this process. I still don’t know why it didn’t work to publish a message directly from SNS, but I’m grateful I found this article. Just test it out with an alarm!

SNS and SQS

You can use both SNS and SQS at once. SNS can send messages to many different subscribers. You can have multiple SQS queues subscribed to SNS, and they all get the same message. This is called “fan-out”.

NOTE: as of this writing, you can only send SNS messages to the standard SQS queues, not FIFO.

When this could be useful: S3 only allows one event rule, so if you want S3 to send message to multiple SQS queues, you could put SNS in between them. This way you send only one message to SNS, but it fans out to many SQS subscribers.