Skip to content

Commit 8c2eaaf

Browse files
authored
Merge pull request #1546 from Laren-AWS/Laren-AWS/sns-examples
Amazon SNS examples
2 parents 7c6928a + 249fc20 commit 8c2eaaf

15 files changed

+728
-247
lines changed

python/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,18 @@ Shows how to use the AWS SDK for Python (Boto3) with Amazon Simple Email Service
301301
* Create and manage rules to block, allow, or handle incoming emails.
302302
* Copy email and domain identity configuration from one AWS Region to another.
303303

304+
### [Amazon Simple Notification Service topics and subscriptions example](https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/python/example_code/sns/README.md)
305+
306+
#### Purpose
307+
308+
Shows how to use the AWS SDK for Python (Boto3) with Amazon Simple Notification Service
309+
(Amazon SNS).
310+
311+
* Create a notification topic.
312+
* Subscribe phone numbers and emails to the topic.
313+
* Publish messages to the topic and receive them at your subscribed endpoints.
314+
* Add filtering attributes to a subscription.
315+
304316
### [Amazon SQS getting started examples](https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/python/example_code/sqs/ReadMe.md)
305317

306318
#### Purpose

python/example_code/s3/s3_basics/ReadMe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Purpose
44

5-
Shows how to use the AWS SDK for Python (Boto3) to get started using bucket and
5+
Shows how to use the AWS SDK for Python (Boto3) to get started using bucket and
66
object operations in Amazon Simple Storage Service (Amazon S3).
77
Learn to create, get, remove, and configure buckets and objects.
88

python/example_code/s3/s3_versioning/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Purpose
44

55
Shows how to use the AWS SDK for Python (Boto3) to set up an Amazon S3 bucket for
6-
versioning, and how to perform taks on a version-enabled bucket. Learn to
6+
versioning, and how to perform tasks on a version-enabled bucket. Learn to
77
accomplish the following tasks:
88

99
* Create a version-enabled bucket and apply revisions to its objects.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# Amazon Simple Notification Service (Amazon SNS) basics example
3+
files:
4+
- path: sns_basics.py
5+
services:
6+
- sns
7+
- path: test/conftest.py
8+
- path: test/test_sns_basics.py
9+
services:
10+
- sns
11+
...

python/example_code/sns/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

python/example_code/sns/sns-python-example-create-topic.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

python/example_code/sns/sns-python-example-list-subscriptions-by-topic.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

python/example_code/sns/sns-python-example-list-subscriptions.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

python/example_code/sns/sns-python-example-list-topics.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

python/example_code/sns/sns-python-example-publish-to-phonenumber.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)