AWS Simple Notfication Services is a pub-sub service - no polling required. SNS is a natural architectural match with SQS or can be used to do mobile push as well.

The basis of the system is a Topic. Many AWS services can publish to a SNS topic. Messages on a topic can be customized based on the subscribing service. Subscriptions must be confirmed and will expires in 3 days if unconfirmed.

Many services can subscribe to an SNS topic - processing can be handled realtime by subscribing a Lambda function or webservice to the topic or processing can be handled in a loosely coupled, as available process, by subscribing a SQS queue to the topic. Protocols include HTTP/HTTPS, email, Email-JSON, SMS, SQS, AWS Lambda and application.

SNS Document Format

The SNS document format is very close to an HTTP request format - which makes a lot of sense seeing that you can send an SNS message to an HTTP/HTTPS endpoint. The name, type, and value fields must not be empty or null and the message body shouldn’t be empty or null either. Here is the format of an SNS message:

POST / HTTP/1.1
  x-amz-sns-message-type: Notification
  x-amz-sns-message-id: 22b80b92-fdea-4c2c-8f9d-bdfb0c7bf324
  x-amz-sns-topic-arn: arn:aws:sns:us-west-2:123456789012:MyTopic
  x-amz-sns-subscription-arn: arn:aws:sns:us-west-2:123456789012:MyTopic:c9135db0-26c4-47ec-8998-413945fb5a96
  Content-Length: 773
  Content-Type: text/plain; charset=UTF-8
  Host: myhost.example.com
  Connection: Keep-Alive
  User-Agent: Amazon Simple Notification Service Agent
  {
    "Type" : "Notification",
    "MessageId" : "22b80b92-fdea-4c2c-8f9d-bdfb0c7bf324",
    "TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
    "Subject" : "My First Message",
    "Message" : "Hello world!",
    "Timestamp" : "2012-05-02T00:54:06.655Z",
    "SignatureVersion" : "1",
    "Signature" : "EXAMPLEw6JRNwm1LFQL4ICB0bnXrdB8ClRMTQFGBqwLpGbM78tJ4etTwC5zU7O3tS6tGpey3ejedNdOJ+1fkIp9F2/LmNVKb5aFlYq+9rk9ZiPph5YlLmWsDcyC5T+Sy9/umic5S0UQc2PEtgdpVBahwNOdMW4JPwk0kAJJztnc=",
    "SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem",
    "UnsubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:123456789012:MyTopic:c9135db0-26c4-47ec-8998-413945fb5a96"
  }

SNS Mobile Push

Mobile Push is the other primary use case for SNS. You need to setup each mobile platform, which is essentially a secure pipe between your AWS endpoint and the mobile provider, before you can use it..

  1. Request credentials from mobile platform - get a login

  2. Get request token from mobile platform - get a thingy that represents your app

  3. Create a Platform Application Object - register it with SNS and get an object you can use with your request

  4. Create a Platform End Point - create an event handler that receives the SNS message and routes it to the mobile platform; a platform end point represents a combination of an app, device, and service.

Once this is done, push a message to the mobile platform end point.

Use Cases

Fan out - Publish to a SNS topic and subscribe a SQS queue to fan out messages to distributed applications.

Platform specific message? Custom message based on platform