Amazon Simple Notification Service Script

Sample Code & Libraries>Amazon Simple Notification Service Script
Community Contributed Software

  • Amazon Web Services provides links to these packages as a convenience for our customers, but software not authored by an "@AWS" account has not been reviewed or screened by AWS.
  • Please review this software to ensure it meets your needs before using it.

This script allows you to automatically confirm a SNS subscription and validate that the request came from Amazon. The script shows you how to receive a SNS message, parse the JSON message, and verify the signature using Amazon's public certificate key.

Details

Submitted By: anton@sprightlysoft.com
AWS Products Used: Amazon SNS
Language(s): C#
License: Microsoft Public License (Ms-PL)
Source Control Access: http://sprightlysoft.com/Download/SprightlySoft_SNSAutoConfirm_v1.0.zip
Created On: April 20, 2011 4:31 AM GMT
Last Updated: April 20, 2011 4:31 AM GMT
Download

Amazon Simple Notification Service (SNS) is a web service that allows you to notify distributed applications by pushing a message to them.

Say you have an application that runs on many servers. In a traditional application the computers would continually poll a queue or database looking for a job to process. Many computers continually polling will reduce performance of the queue and result in higher usage fees. You can increase the time between polls to reduce load but this decreases the performance of your application.

One way to have your computers process a job immediately and eliminate the need to poll a queue is to use Amazon's Simple Notification Service. First you set up a web server on each of the computers that run your application. Next, set up a SNS subscription in Amazon to send messages to your computers. Then create an application on your web servers to do something when they receive a SNS message. Finally, configure your application to call SNS when something needs to be done.

Here is a representation of the flow: Your application --> Amazon SNS --> Your web servers --> Do work

To get familiar with Amazon SNS you can log into the AWS Console with your Amazon credentials. Start by creating a Topic and add a Subscription that will specify where the messages will go. You can send a message to an email address, web site URL, or an Amazon Simple Queue Service queue.

When you create a subscription you will need to confirm you have permission to send messages there. With an email subscription you will be sent an email and you will need to click a link in that email. When you create a web URL subscription Amazon sends a message to that URL. You will need to capture this message and respond to it by loading a special URL in the message or calling the API with a token that is included in the message. If you do not confirm the subscription, Amazon will not send messages to it.

The process of configuring a web URL to receive a SNS message is tricky. You need to configure the web server before you set up the subscription. The following describes how to set up a Windows web server to respond to Amazon SNS messages. The main points of the article are setting up a script to automatically confirm a SNS subscription and to verify that the SNS message came from Amazon.

Visit http://sprightlysoft.com/blog/?p=71 to view the full article including source code snippets.

©2014, Amazon Web Services, Inc. or its affiliates. All rights reserved.