| 
 | 1 | +# Amazon Simple Notification Service topics and subscriptions example  | 
 | 2 | + | 
 | 3 | +## Purpose  | 
 | 4 | + | 
 | 5 | +Shows how to use the AWS SDK for Python (Boto3) with Amazon Simple Notification Service  | 
 | 6 | +(Amazon SNS).  | 
 | 7 | + | 
 | 8 | +* Create a notification topic.  | 
 | 9 | +* Subscribe phone numbers and emails to the topic.  | 
 | 10 | +* Publish messages to the topic and receive them at your subscribed endpoints.  | 
 | 11 | +* Add filtering attributes to a subscription.  | 
 | 12 | + | 
 | 13 | +## Prerequisites  | 
 | 14 | + | 
 | 15 | +- You must have an AWS account, and have your default credentials and AWS Region  | 
 | 16 | + configured as described in the [AWS Tools and SDKs Shared Configuration and  | 
 | 17 | + Credentials Reference Guide](https://docs.aws.amazon.com/credref/latest/refdocs/creds-config-files.html).  | 
 | 18 | +- Python 3.8.5 or later  | 
 | 19 | +- Boto3 1.15.4 or later  | 
 | 20 | +- PyTest 5.3.5 or later (to run unit tests)  | 
 | 21 | + | 
 | 22 | +## Cautions  | 
 | 23 | + | 
 | 24 | +- As an AWS best practice, grant this code least privilege, or only the   | 
 | 25 | + permissions required to perform a task. For more information, see   | 
 | 26 | + [Grant Least Privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege)   | 
 | 27 | + in the *AWS Identity and Access Management   | 
 | 28 | + User Guide*.  | 
 | 29 | +- This code has not been tested in all AWS Regions. Some AWS services are   | 
 | 30 | + available only in specific Regions. For more information, see the   | 
 | 31 | + [AWS Region Table](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)  | 
 | 32 | + on the AWS website.  | 
 | 33 | +- Running this code might result in charges to your AWS account.  | 
 | 34 | + | 
 | 35 | +## Running the code  | 
 | 36 | + | 
 | 37 | +Run this example at a command prompt with the following command.  | 
 | 38 | + | 
 | 39 | +```  | 
 | 40 | +python sns_basics.py  | 
 | 41 | +```   | 
 | 42 | + | 
 | 43 | +### Example structure  | 
 | 44 | + | 
 | 45 | +The example contains the following files.  | 
 | 46 | + | 
 | 47 | +**sns_basics.py**  | 
 | 48 | + | 
 | 49 | +Shows how to use Amazon SNS to subscribe to a topic and receive messages.  | 
 | 50 | + | 
 | 51 | +1. Creates a notification topic.  | 
 | 52 | +2. Sends a message directly to a phone number.  | 
 | 53 | +3. Subscribes an email and a phone number to the topic.  | 
 | 54 | +4. Publishes a multi-format message to the topic. Subscribers receive different  | 
 | 55 | +messages depending on their notification protocol.  | 
 | 56 | +5. Adds an attribute filter to the phone number subscription and publishes messages  | 
 | 57 | +to the topic. Only messages with matching filters are sent to the phone number.  | 
 | 58 | + | 
 | 59 | +## Running the tests  | 
 | 60 | + | 
 | 61 | +The unit tests in this module use the botocore Stubber. This captures requests before   | 
 | 62 | +they are sent to AWS, and returns a mocked response. To run all of the tests,   | 
 | 63 | +run the following command in your [GitHub root]/python/example_code/sns  | 
 | 64 | +folder.  | 
 | 65 | + | 
 | 66 | +```   | 
 | 67 | +python -m pytest  | 
 | 68 | +```  | 
 | 69 | + | 
 | 70 | +## Additional information  | 
 | 71 | + | 
 | 72 | +- [Boto3 Amazon SNS service reference](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sns.html)  | 
 | 73 | +- [Amazon Simple Notification Service documentation](https://docs.aws.amazon.com/sns/index.html)  | 
 | 74 | + | 
 | 75 | +---  | 
 | 76 | +Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.  | 
 | 77 | + | 
 | 78 | +SPDX-License-Identifier: Apache-2.0  | 
0 commit comments