AWS Simple Notification 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. FIFO topics order messages by message group ID and are deduplicated; FIFO topics can only have FIFO SQS queues as subscribers.
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 endpoints, email, Email-JSON, SMS, SQS, Lambda, and Kinesis Firehose. To keep subscribers from getting every message, a message filter policy enables subscribers to get just the subset of messages they need.
Data is encrypted in flight using HTTPS and at rest using KMS keys. IAM policies and resources policies, in this case called SNS Access Policies, apply.
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.
SNS defines a Delivery Policy for each delivery protocol. The delivery policy defines how SNS retries the delivery of messages when server-side errors occur (when the system that hosts the subscribed endpoint becomes unavailable). When the delivery policy is exhausted, SNS stops retrying the delivery and discards the message—unless a dead-letter queue is attached to the subscription. HTTP/S endpoints are the only delivery mechanism that supports custom policies. Unless you have defined a Dead Letter Queue (DLQ) for the subscription the message is discarded if delivery isn’t successful. The DLQ must be the same type of topic - FIFO topic -> FIFO DLQ topic; Standard topic -> Standard DLQ topic.
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.. this might also be called Direct Publish.
- Request credentials from mobile platform - get a login
- Get request token from mobile platform - get a thingy that represents your app
- Create a Platform Application Object - register it with SNS and get an object you can use with your request
- 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.
many loosely coupled consumers? SNS => SQS queue to fan out many loosely coupled consumers order sensitive? SNS FIFO => SQS FIFO