Exploring Features in Amazon SNS: Delivery Policies and Message Formatting
Amazon Simple Notification Service (SNS) is a powerful service that enables you to send messages to multiple endpoints. Whether you are new to AWS or an experienced user, understanding the latest features can enhance your experience and improve your applications. In this blog post, we'll explore two new features introduced in Amazon SNS: Delivery Policies and Message Formatting.
Introduction to Amazon SNS
Amazon SNS allows you to create named Topics, subscribe to these Topics (with delivery options including email, HTTP/HTTPS, SMS, or an SQS queue), and publish messages to these Topics. It is a flexible, fully managed pub/sub messaging service that can be used to decouple and scale microservices, distributed systems, and serverless applications.
SNS Delivery Policies
The new SNS Delivery Policies feature gives you more control over how your messages are delivered, helping to manage delivery rates and error handling for each SNS endpoint. This is particularly useful when you need to avoid overwhelming a particular endpoint with a sudden influx of messages.
Key Components of Delivery Policies
- Retry Policy: Controls how retries are handled when message delivery fails.
- Throttle Policy: Manages the rate of message delivery to avoid overwhelming the endpoint.
Retry Policy Options
The Retry Policy includes several configurable options:
- minDelayTarget: The minimum delay for a retry.
- maxDelayTarget: The maximum delay for a retry.
- numNoDelayRetries: Number of retries to be done without delay.
- numMinDelayRetries: Number of retries at
minDelayTarget
intervals before initiating the backoff function.
- numMaxDelayRetries: Number of retries at
maxDelayTarget
during the backoff function.
- backoffFunction: The model for backoff between retries, which can be Linear, Exponential, or Arithmetic.
Here is an example of how you might configure a Retry Policy in JSON format:
{
"minDelayTarget": 20,
"maxDelayTarget": 20,
"numNoDelayRetries": 3,
"numMinDelayRetries": 2,
"numMaxDelayRetries": 2,
"backoffFunction": "linear"
}
Throttle Policy Options
The Throttle Policy has a single configurable option:
- maxReceivesPerSecond: The maximum number of delivery attempts per second per subscription.
An example Throttle Policy in JSON format might look like this:
{
"maxReceivesPerSecond": 1
}
Combining Policies
All message delivery attempts are governed by an "effective Delivery Policy" that combines the default policy with any custom policies you have set at the Topic and Subscription levels. Unspecified values at the Subscription level inherit from the Topic’s Delivery Policy, which in turn inherits from the default polic
SNS Message Formatting
The second feature, SNS Message Formatting, allows you to tailor the message content based on the type of subscription. This means you can send different messages to email, SMS, HTTP/HTTPS, or SQS endpoints.
How to Use Message Formatting
To use this feature, set the MessageStructure
parameter to json
when calling the SNS publish function. The message body must then contain a JSON object with a default message and optional messages for each protocol.
Here’s an example:
{
"default": "Server busy.",
"email": "Dear Jeff, your server is really busy and you should investigate. Best Regards, AWS.",
"sms": "ALERT! Server Busy!!",
"https": "ServerBusy"
}
In this example:
- The
default
message is used for protocols like HTTP and SQS that don’t have specific entries.
- The
email
entry sends a detailed message to email subscribers.
- The
sms
entry sends a concise alert to SMS subscribers.
- The
https
entry sends a simple message to HTTPS endpoints.
Example Code Snippet
Here’s how you can publish a message with different formats for each protocol using the AWS SDK for Python (Boto3):

Conclusion
Amazon SNS’s new Delivery Policies and Message Formatting features provide enhanced control and flexibility in managing your messaging needs. Delivery Policies allow you to fine-tune retry and throttle settings, ensuring your endpoints are not overwhelmed. Message Formatting lets you customize messages for different types of endpoints, improving communication effectiveness.
By leveraging these features, you can optimize message delivery and ensure that the right message reaches the right audience through the right channel. Whether you're new to AWS or an experienced user, these additions to Amazon SNS will help you build more robust and efficient messaging solutions.
Author / Developer : Divyansh Patel
Reference : https://aws.amazon.com/de/blogs/aws/new-features-for-amazon-sns-delivery-policies-and-message-formatting/