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.

commit()[source]

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

compare_message_attributtes(message_attributes)[source]

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

Parameters:

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

create_subscription(topic_arn, protocol, endpoint)[source]

Create a subscription to the topic

Parameters:
  • 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_topic(topic_name)[source]

Create a new topic name

Parameters:

topic_name (str) – New topic name to create

Returns:

New topic ARN

Return type:

str

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

Returns:

Type and value of an attribute

Return type:

dict

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.

Parameters:
  • 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.

set_message_attributes(message_attributes)[source]

Validate attribute value and set new value

set_separator(separator)[source]

Set custom separator for messages from the queue