SNS Manager

View Licence Agreement

class sosw.components.sns.SnsManager(**kwargs)[source]

AWS Simple Notification System Manager helper. Requires the Role to have permissions to access SSM for requested resources, something like.

Must have a recipient specified either during initialization or later using set_recipient method. Messages received by send_message() are batched and will be actually send to SNS only during the call of commit() or during the destruction of the class.

The method doesn’t yet support batching messages for multiple recipients, so in case you try to change the recipient it automatically sends all the currently batched messages to the previous recipient.


Combines messages from self.queue and pushes them to self.recipient. Cleans the queue after that.


Compare MessageAttributes. If new object was received - set new value to the attribute


message_attributes (dict) – Message attributes for SNS subscription filter policies

create_subscription(topic_arn, protocol, endpoint)[source]

Create a subscription to the topic

  • topic_arn (str) – ARN of a topic

  • protocol (str) – The type of endpoint to subscribe

  • endpoint (str) – Endpoint that can receive notifications from Amazon SNS


Create a new topic name


topic_name (str) – New topic name to create


New topic ARN

Return type:


static get_message_attribute(attribute)[source]

Amazon SNS compares policy attributes only to message attributes that have the following data types: - String - String.Array - Number


Type and value of an attribute

Return type:


send_message(message, subject=None, forse_commit=False, message_attributes=None)[source]

If the subject is not yet set (for example during __init__() of the class) - then require subject to be set. Otherwize we accept None subject and simply append messages to queue. Once the subject changes - the queue is commite automatically.

  • message (str) – Message to be send in body of SNS message. Queued.

  • subject (str) – Optional. Custom subject for message.

  • forse_commit (bool) – Commit the queue immediately if True, by default False

  • message_attributes (dict) – Optional. Message attributes for SNS subscription filter policies

set_client_attr(name, value)[source]

Sets the given _name_ attribute to _value_. Commits the self.queue if there are any messages in it.


Validate attribute value and set new value


Set custom separator for messages from the queue