View on GitHub

Automation for AWS VPC management, built on top of boto.

 
 
veep.SNS
index
/Users/mghali/work/veep/veep/SNS.py

 
Modules
       
boto

 
Classes
       
__builtin__.object
Topic
boto.sns.connection.SNSConnection(boto.connection.AWSQueryConnection)
SNSConnection

 
class SNSConnection(boto.sns.connection.SNSConnection)
    
Method resolution order:
SNSConnection
boto.sns.connection.SNSConnection
boto.connection.AWSQueryConnection
boto.connection.AWSAuthConnection
__builtin__.object

Methods defined here:
__init__(self, **kwargs)
create_topic(self, name)
get_all_topics(self)
get_topic(self, name)

Methods inherited from boto.sns.connection.SNSConnection:
add_permission(self, topic, label, account_ids, actions)
Adds a statement to a topic's access control policy, granting
access for the specified AWS accounts to the specified actions.
 
:type topic: string
:param topic: The ARN of the topic.
 
:type label: string
:param label: A unique identifier for the new policy statement.
 
:type account_ids: list of strings
:param account_ids: The AWS account ids of the users who will be
                    give access to the specified actions.
 
:type actions: list of strings
:param actions: The actions you want to allow for each of the
                specified principal(s).
confirm_subscription(self, topic, token, authenticate_on_unsubscribe=False)
Get properties of a Topic
 
:type topic: string
:param topic: The ARN of the new topic.
 
:type token: string
:param token: Short-lived token sent to and endpoint during
              the Subscribe operation.
 
:type authenticate_on_unsubscribe: bool
:param authenticate_on_unsubscribe: Optional parameter indicating
                                    that you wish to disable
                                    unauthenticated unsubscription
                                    of the subscription.
create_platform_application(self, name=None, platform=None, attributes=None)
The `CreatePlatformApplication` action creates a platform
application object for one of the supported push notification
services, such as APNS and GCM, to which devices and mobile
apps may register. You must specify PlatformPrincipal and
PlatformCredential attributes when using the
`CreatePlatformApplication` action. The PlatformPrincipal is
received from the notification service. For APNS/APNS_SANDBOX,
PlatformPrincipal is "SSL certificate". For GCM,
PlatformPrincipal is not applicable. For ADM,
PlatformPrincipal is "client id". The PlatformCredential is
also received from the notification service. For
APNS/APNS_SANDBOX, PlatformCredential is "private key". For
GCM, PlatformCredential is "API key". For ADM,
PlatformCredential is "client secret". The
PlatformApplicationArn that is returned when using
`CreatePlatformApplication` is then used as an attribute for
the `CreatePlatformEndpoint` action. For more information, see
`Using Amazon SNS Mobile Push Notifications`_.
 
:type name: string
:param name: Application names must be made up of only uppercase and
    lowercase ASCII letters, numbers, underscores, hyphens, and
    periods, and must be between 1 and 256 characters long.
 
:type platform: string
:param platform: The following platforms are supported: ADM (Amazon
    Device Messaging), APNS (Apple Push Notification Service),
    APNS_SANDBOX, and GCM (Google Cloud Messaging).
 
:type attributes: map
:param attributes: For a list of attributes, see
    `SetPlatformApplicationAttributes`_
create_platform_endpoint(self, platform_application_arn=None, token=None, custom_user_data=None, attributes=None)
The `CreatePlatformEndpoint` creates an endpoint for a device
and mobile app on one of the supported push notification
services, such as GCM and APNS. `CreatePlatformEndpoint`
requires the PlatformApplicationArn that is returned from
`CreatePlatformApplication`. The EndpointArn that is returned
when using `CreatePlatformEndpoint` can then be used by the
`Publish` action to send a message to a mobile app or by the
`Subscribe` action for subscription to a topic. For more
information, see `Using Amazon SNS Mobile Push
Notifications`_.
 
:type platform_application_arn: string
:param platform_application_arn: PlatformApplicationArn returned from
    CreatePlatformApplication is used to create a an endpoint.
 
:type token: string
:param token: Unique identifier created by the notification service for
    an app on a device. The specific name for Token will vary,
    depending on which notification service is being used. For example,
    when using APNS as the notification service, you need the device
    token. Alternatively, when using GCM or ADM, the device token
    equivalent is called the registration ID.
 
:type custom_user_data: string
:param custom_user_data: Arbitrary user data to associate with the
    endpoint. SNS does not use this data. The data must be in UTF-8
    format and less than 2KB.
 
:type attributes: map
:param attributes: For a list of attributes, see
    `SetEndpointAttributes`_.
delete_endpoint(self, endpoint_arn=None)
The `DeleteEndpoint` action, which is idempotent, deletes the
endpoint from SNS. For more information, see `Using Amazon SNS
Mobile Push Notifications`_.
 
:type endpoint_arn: string
:param endpoint_arn: EndpointArn of endpoint to delete.
delete_platform_application(self, platform_application_arn=None)
The `DeletePlatformApplication` action deletes a platform
application object for one of the supported push notification
services, such as APNS and GCM. For more information, see
`Using Amazon SNS Mobile Push Notifications`_.
 
:type platform_application_arn: string
:param platform_application_arn: PlatformApplicationArn of platform
    application object to delete.
delete_topic(self, topic)
Delete an existing topic
 
:type topic: string
:param topic: The ARN of the topic
get_all_subscriptions(self, next_token=None)
Get list of all subscriptions.
 
:type next_token: string
:param next_token: Token returned by the previous call to
                   this method.
get_all_subscriptions_by_topic(self, topic, next_token=None)
Get list of all subscriptions to a specific topic.
 
:type topic: string
:param topic: The ARN of the topic for which you wish to
              find subscriptions.
 
:type next_token: string
:param next_token: Token returned by the previous call to
                   this method.
get_endpoint_attributes(self, endpoint_arn=None)
The `GetEndpointAttributes` retrieves the endpoint attributes
for a device on one of the supported push notification
services, such as GCM and APNS. For more information, see
`Using Amazon SNS Mobile Push Notifications`_.
 
:type endpoint_arn: string
:param endpoint_arn: EndpointArn for GetEndpointAttributes input.
get_platform_application_attributes(self, platform_application_arn=None)
The `GetPlatformApplicationAttributes` action retrieves the
attributes of the platform application object for the
supported push notification services, such as APNS and GCM.
For more information, see `Using Amazon SNS Mobile Push
Notifications`_.
 
:type platform_application_arn: string
:param platform_application_arn: PlatformApplicationArn for
    GetPlatformApplicationAttributesInput.
get_topic_attributes(self, topic)
Get attributes of a Topic
 
:type topic: string
:param topic: The ARN of the topic.
list_endpoints_by_platform_application(self, platform_application_arn=None, next_token=None)
The `ListEndpointsByPlatformApplication` action lists the
endpoints and endpoint attributes for devices in a supported
push notification service, such as GCM and APNS. The results
for `ListEndpointsByPlatformApplication` are paginated and
return a limited list of endpoints, up to 100. If additional
records are available after the first page results, then a
NextToken string will be returned. To receive the next page,
you call `ListEndpointsByPlatformApplication` again using the
NextToken string received from the previous call. When there
are no more records to return, NextToken will be null. For
more information, see `Using Amazon SNS Mobile Push
Notifications`_.
 
:type platform_application_arn: string
:param platform_application_arn: PlatformApplicationArn for
    ListEndpointsByPlatformApplicationInput action.
 
:type next_token: string
:param next_token: NextToken string is used when calling
    ListEndpointsByPlatformApplication action to retrieve additional
    records that are available after the first page results.
list_platform_applications(self, next_token=None)
The `ListPlatformApplications` action lists the platform
application objects for the supported push notification
services, such as APNS and GCM. The results for
`ListPlatformApplications` are paginated and return a limited
list of applications, up to 100. If additional records are
available after the first page results, then a NextToken
string will be returned. To receive the next page, you call
`ListPlatformApplications` using the NextToken string received
from the previous call. When there are no more records to
return, NextToken will be null. For more information, see
`Using Amazon SNS Mobile Push Notifications`_.
 
:type next_token: string
:param next_token: NextToken string is used when calling
    ListPlatformApplications action to retrieve additional records that
    are available after the first page results.
publish(self, topic=None, message=None, subject=None, target_arn=None, message_structure=None, message_attributes=None)
Get properties of a Topic
 
:type topic: string
:param topic: The ARN of the new topic.
 
:type message: string
:param message: The message you want to send to the topic.
                Messages must be UTF-8 encoded strings and
                be at most 4KB in size.
 
:type message_structure: string
:param message_structure: Optional parameter. If left as ``None``,
                          plain text will be sent. If set to ``json``,
                          your message should be a JSON string that
                          matches the structure described at
                          http://docs.aws.amazon.com/sns/latest/dg/PublishTopic.html#sns-message-formatting-by-protocol
 
:type message_attributes: dict
:param message_attributes: Message attributes to set. Should be
    of the form:
 
    .. code-block:: python
 
        {
            "name1": {
                "data_type": "Number",
                "string_value": "42"
            },
            "name2": {
                "data_type": "String",
                "string_value": "Bob"
            }
        }
 
:type subject: string
:param subject: Optional parameter to be used as the "Subject"
                line of the email notifications.
 
:type target_arn: string
:param target_arn: Optional parameter for either TopicArn or
                   EndpointArn, but not both.
remove_permission(self, topic, label)
Removes a statement from a topic's access control policy.
 
:type topic: string
:param topic: The ARN of the topic.
 
:type label: string
:param label: A unique identifier for the policy statement
              to be removed.
set_endpoint_attributes(self, endpoint_arn=None, attributes=None)
The `SetEndpointAttributes` action sets the attributes for an
endpoint for a device on one of the supported push
notification services, such as GCM and APNS. For more
information, see `Using Amazon SNS Mobile Push
Notifications`_.
 
:type endpoint_arn: string
:param endpoint_arn: EndpointArn used for SetEndpointAttributes action.
 
:type attributes: map
:param attributes:
A map of the endpoint attributes. Attributes in this map include the
    following:
 
 
+ `CustomUserData` -- arbitrary user data to associate with the
      endpoint. SNS does not use this data. The data must be in UTF-8
      format and less than 2KB.
+ `Enabled` -- flag that enables/disables delivery to the endpoint.
      Message Processor will set this to false when a notification
      service indicates to SNS that the endpoint is invalid. Users can
      set it back to true, typically after updating Token.
+ `Token` -- device token, also referred to as a registration id, for
      an app and mobile device. This is returned from the notification
      service when an app and mobile device are registered with the
      notification service.
set_platform_application_attributes(self, platform_application_arn=None, attributes=None)
The `SetPlatformApplicationAttributes` action sets the
attributes of the platform application object for the
supported push notification services, such as APNS and GCM.
For more information, see `Using Amazon SNS Mobile Push
Notifications`_.
 
:type platform_application_arn: string
:param platform_application_arn: PlatformApplicationArn for
    SetPlatformApplicationAttributes action.
 
:type attributes: map
:param attributes:
A map of the platform application attributes. Attributes in this map
    include the following:
 
 
+ `PlatformCredential` -- The credential received from the notification
      service. For APNS/APNS_SANDBOX, PlatformCredential is "private
      key". For GCM, PlatformCredential is "API key". For ADM,
      PlatformCredential is "client secret".
+ `PlatformPrincipal` -- The principal received from the notification
      service. For APNS/APNS_SANDBOX, PlatformPrincipal is "SSL
      certificate". For GCM, PlatformPrincipal is not applicable. For
      ADM, PlatformPrincipal is "client id".
+ `EventEndpointCreated` -- Topic ARN to which EndpointCreated event
      notifications should be sent.
+ `EventEndpointDeleted` -- Topic ARN to which EndpointDeleted event
      notifications should be sent.
+ `EventEndpointUpdated` -- Topic ARN to which EndpointUpdate event
      notifications should be sent.
+ `EventDeliveryFailure` -- Topic ARN to which DeliveryFailure event
      notifications should be sent upon Direct Publish delivery failure
      (permanent) to one of the application's endpoints.
set_topic_attributes(self, topic, attr_name, attr_value)
Get attributes of a Topic
 
:type topic: string
:param topic: The ARN of the topic.
 
:type attr_name: string
:param attr_name: The name of the attribute you want to set.
                  Only a subset of the topic's attributes are mutable.
                  Valid values: Policy | DisplayName
 
:type attr_value: string
:param attr_value: The new value for the attribute.
subscribe(self, topic, protocol, endpoint)
Subscribe to a Topic.
 
:type topic: string
:param topic: The ARN of the new topic.
 
:type protocol: string
:param protocol: The protocol used to communicate with
                 the subscriber.  Current choices are:
                 email|email-json|http|https|sqs|sms|application
 
:type endpoint: string
:param endpoint: The location of the endpoint for
                 the subscriber.
                 * For email, this would be a valid email address
                 * For email-json, this would be a valid email address
                 * For http, this would be a URL beginning with http
                 * For https, this would be a URL beginning with https
                 * For sqs, this would be the ARN of an SQS Queue
                 * For sms, this would be a phone number of an
                   SMS-enabled device
                 * For application, the endpoint is the EndpointArn
                   of a mobile app and device.
subscribe_sqs_queue(self, topic, queue)
Subscribe an SQS queue to a topic.
 
This is convenience method that handles most of the complexity involved
in using an SQS queue as an endpoint for an SNS topic.  To achieve this
the following operations are performed:
 
* The correct ARN is constructed for the SQS queue and that ARN is
  then subscribed to the topic.
* A JSON policy document is contructed that grants permission to
  the SNS topic to send messages to the SQS queue.
* This JSON policy is then associated with the SQS queue using
  the queue's set_attribute method.  If the queue already has
  a policy associated with it, this process will add a Statement to
  that policy.  If no policy exists, a new policy will be created.
 
:type topic: string
:param topic: The ARN of the new topic.
 
:type queue: A boto Queue object
:param queue: The queue you wish to subscribe to the SNS Topic.
unsubscribe(self, subscription)
Allows endpoint owner to delete subscription.
Confirmation message will be delivered.
 
:type subscription: string
:param subscription: The ARN of the subscription to be deleted.

Data and other attributes inherited from boto.sns.connection.SNSConnection:
APIVersion = '2010-03-31'
DefaultRegionEndpoint = 'sns.us-east-1.amazonaws.com'
DefaultRegionName = 'us-east-1'

Methods inherited from boto.connection.AWSQueryConnection:
build_complex_list_params(self, params, items, label, names)
Serialize a list of structures.
 
For example::
 
    items = [('foo', 'bar', 'baz'), ('foo2', 'bar2', 'baz2')]
    label = 'ParamName.member'
    names = ('One', 'Two', 'Three')
    build_complex_list_params(params, items, label, names)
 
would result in the params dict being updated with these params::
 
    ParamName.member.1.One = foo
    ParamName.member.1.Two = bar
    ParamName.member.1.Three = baz
 
    ParamName.member.2.One = foo2
    ParamName.member.2.Two = bar2
    ParamName.member.2.Three = baz2
 
:type params: dict
:param params: The params dict.  The complex list params
    will be added to this dict.
 
:type items: list of tuples
:param items: The list to serialize.
 
:type label: string
:param label: The prefix to apply to the parameter.
 
:type names: tuple of strings
:param names: The names associated with each tuple element.
build_list_params(self, params, items, label)
get_list(self, action, params, markers, path='/', parent=None, verb='GET')
get_object(self, action, params, cls, path='/', parent=None, verb='GET')
get_status(self, action, params, path='/', parent=None, verb='GET')
get_utf8_value(self, value)
make_request(self, action, params=None, path='/', verb='GET')

Data and other attributes inherited from boto.connection.AWSQueryConnection:
ResponseError = <class 'boto.exception.BotoServerError'>

Methods inherited from boto.connection.AWSAuthConnection:
__repr__(self)
build_base_http_request(self, method, path, auth_path, params=None, headers=None, data='', host=None)
close(self)
(Optional) Close any open HTTP connections.  This is non-destructive,
and making a new request will open a connection again.
get_http_connection(self, host, port, is_secure)
get_path(self, path='/')
get_proxy_auth_header(self)
get_proxy_url_with_auth(self)
# For passing proxy information to other connection libraries, e.g. cloudsearch2
handle_proxy(self, proxy, proxy_port, proxy_user, proxy_pass)
new_http_connection(self, host, port, is_secure)
prefix_proxy_to_path(self, path, host=None)
proxy_ssl(self, host=None, port=None)
put_http_connection(self, host, port, is_secure, connection)
server_name(self, port=None)
set_host_header(self, request)
set_request_hook(self, hook)
skip_proxy(self, host)

Data descriptors inherited from boto.connection.AWSAuthConnection:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
access_key
auth_region_name
auth_service_name
aws_access_key_id
aws_secret_access_key
connection
gs_access_key_id
gs_secret_access_key
profile_name
secret_key

 
class Topic(__builtin__.object)
     Methods defined here:
__cmp__(self, obj)
__init__(self, connection, topic_res)
__repr__(self)
__str__(self)
get_subscriptions(self)
subscribe(self, sub)
unsubscribe(self, sub_arn)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
connect_to_region(region_name, **kw_params)
Given a valid region name, return a
:class:`veep.IAM.SNSConnection`.
 
:type: str
:param region_name: The name of the region to connect to.
 
:rtype: :class:`veep.IAM.SNSConnection` or ``None``
:return: A connection to the given region, or None if an invalid region
         name is given