Processing SNS Messages

Learn how messages are published, delivered, and monitored in Amazon SNS.

The data sent from a producer to an SNS topic in Amazon SNS is known as a message. This message is then distributed to all of the subscribers of the topic. Let’s look at the different features Amazon SNS provides us to publish and receive messages.

Publishing messages

After creating an SNS topic and adding subscribers, we can publish messages to a topic using the AWS Management Console or the AWS SDK. The maximum size of the message we can publish is 256 KB, however, we can extend this size by using the Extended Client Libraries for Java and Python

Using these libraries, we can extend the maximum message size to 2 GB. These libraries work by storing the actual payload of our message in an S3 bucket and sending the reference to this bucket to the subscribers of the SNS topic. Once the subscriber receives this reference, they can de-reference it using the client libraries and retrieve the original message sent by the publisher.

Amazon SNS also allows us to publish up to 10 messages in batches, rather than publishing one message at a time to an SNS topic. Through this, we can significantly reduce the cost of sending notifications in our applications.

Delivering raw messages

Amazon SNS provides the option of sending raw messages to ensure SQS, Kinesis Data Firehose, and HTTP/S endpoints don’t accidentally process the JSON formatting of the messages sent from a topic. If this option is enabled, any metadata SNS adds to a message during publishing or delivering a message is removed.

Following is an example of a message an SNS topic delivers to its subscribers when raw message delivery is disabled:

Get hands-on with 1200+ tech skills courses.