Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
  • Overview
  • Transcript

2.5 SNS: Push Notifications

While queues are good for processing data, push notifications are great for broadcasting. Using SNS (Simple Notification Service) Topics, you can send a message to multiple subscribers at once. You can also use mobile device notifications to send the same message to phones. In this lesson, we are going to use SNS to create messages with a web interface and forward them to SQS so they can be processed by the consumer we created in the last lesson.

2.5 SNS: Push Notifications

Hi, welcome back to explore Amazon Web Services. In this lesson we will look at the simple modification services, SNS. Amazon's implementation of the topic button. While queues only have one consumer that takes a message, topics and messages to all clients that are currently listening. Those putting messages into the topic are called publishers. Those receiving them are called subscribers. So let's again create a topic for order_processing. I'll also set the display name, which would be used for outgoing text messages, which are also a possibility in SNS. But I look at subscription options in a moment. I will copy the ARN as we need to reference it when using the topic. Let me first create a producer. I know, I said they are called publishers here. But I want it to be consistent with the other examples. This time I'm going to create a static HTML page that creates those messages. You can input the AWS SDK directly into your site using MSNCDN. I will first create some HTML text fields for ID and key as well as a text area for the message itself. Then a little area to display the output. Now onto the JavaScript. First we create a function that gets called by clicking the Send Payload button. We need to initialize the AWS config without credentials which we take from the input fields. Then we have to set the region. Next we can initialize our SNS object using the ARN and publish the message from the payload text area. And they call that real lock and error to console or output the received data on the screen. Since this form would look pretty ugly on screen I will prettify it quickly off camera using pitta bootstrap. There we go. Let's check it out in the browser. Sweet. Our own little interface to kick off order processing. Let's add some data and start working. The output tells us the message has been successfully sent. That's great but sadly no one was listening. Our aura is lost. Let's go back to the SNS console and create a subscription. As you can see you have a bunch of options here. You can either call a HTTP, end point, send an email, push it to a mobile application, execute a function. Or what we are going to do, hand it on to a message queue. Note that these options are just permanent subscriptions AWS offers to deliver by itself. You could always subscribe to a topic using the SDK. We also need to allow SNS to put messages into the queue. To make it quicker, I'm not going to mess with very specific policies, but just allow everyone to send messages. Before we post our next message, let's start our consumer from the previous lesson. Then we can send the data and when we check our shell and lock the processing. Now, in addition to the common published subscribe pattern we can also send push notification to mobile devices. SNS supports various Android solutions, Apple push notifications, and Microsoft's notifications for Windows Phone 7 or higher. You now know about topics and MSN's implementation of it in SNS. I would definitely check it out if you want to do push notifications to your phone. Because maintaining your own server for that can be quite a pain. In the next lesson we will look at the data store. See you there.

Back to the top