Simple Notification Service (SNS)

Icon

SNS Icon

Basics

  • When more that one receiver are interested in a message and needs to be processed, rather than using direct integration, one must prefer using SNS.

  • It is a managed service.

  • A typical architecuture looks like below,

  • This pattern is called Pub/Sub pattern, useful when many different consumers are interested in same message.

Publishers

  • Actors/Services responsible to send message to SNS Topic.

Subscribers

  • Actors/Services interested in receiving message from SNS Topic.

SNS Topic

  • Topic is a logical access point and communication channel.

  • event producer (Publisher/s) only sends message to one SNS topic.

  • Many services like CloudWatch Alarms, ASG, CFT changes, AWS Budgets, Lambda, DynamoDB, RDS Events, DMS etc can send data directly to SNS Topic for notifications.

  • event receivers (subscriber/s) will listen to SNS topic notifications and receive all messages from this topic. Subscriber/s may receive specific messages from this topic, by filtering them.

  • 12,50,00,000 subscribers can subscribe to one topic. Subscribers can be SQS, Email Service, Mobile Notification, HTTP endpoints, Kinesis Data Firehose (not Kinesis Data Stream) etc

  • About 100,000 topics can be created and limit can be increased.

  • SNS can be integrated with other AWS services like SQS, Lambda, Kinesis Data Firehose etc.

  • There are two ways to publish,

    • Topic Publish (for AWS SDK)

    • Direct Publish (for mobile SDKs)

Steps to Topic publish (using SDK)

  1. Create a Topic

  2. Create a subscription

  3. Publish to topic

Steps to Direct publish (using Mobile apps SDK)

  1. Create a platform application

  2. Create a platform endpoint

  3. Publish to the platform endpoint

    • It works with Google GCM, Apple APNS, Amazon ADM to receive notifications.

Message Filtering

  • This is a JSON policy used to filter messages sent to SNS topic's subscription.

  • If a subscription does not have message filtering then it will receive every message.

Types of SNS Topics

  • There are basically two types.

Standard Topic

  • Does not ensure ordering of message delivery.

  • Subscribers can be HTTP/HTTPS endpoint, SQS queues, Lambda, mobile applications endpoint, Email, SMS, Kinesis Data firehose etc.

FIFO Topic

  • Ensures ordering of message delivery.

  • Subscribers can be both SQS Standard and FIFO queue.

  • Offers deduplication same as SQS FIFO.

  • Offers messaage group based ordering same as SQS FIFO.

  • Throughput is also similar to SQS FIFO queue.

  • Subscribers can only be SQS queues.

  • Name of fifo topic has be to suffixed with .fifo.

SNS Security

  • Offers in-flight encryption using HTTPS API.

  • Can also have at rest encryption using KMS keys.

  • Client-side encryption can also be done if the client wants to perform encryption/decryption itself.

Access Control

  • AWS IAM policies

    • Can be used to control access to SNS API.

  • SNS Access policy

    • Can also be used to control the access, which is useful when needed to make a cross account access or control access to write to SNS Topic by other AWS services.

Last updated