'Any boto3 sns methods for adding subscribers into a topic etc
I am looking to build a lambda script, where I will be able to:
- List all the SNS topics that I have currently
- Compare with a list/database/table to see if any topics are not in the existing list
- Create the topics
- Add subscribers into them
- Track their subscription status
- Once confirmed, send them the very last SNS notification
On a very rough level, I can accomplish some of the above tasks with the following methods:
- import boto3 -> list_topics()
- parse value from parameter store to obtain a dictionary of topic_name and topic_arn as key-value pair. Compare with the result of list_topic()
- create_topic()
- ???
- list_subscriptions()/list_subscriptions_by_topic()
- ???
Does anyone know how I can accomplish step 4 and 6?
For step 6, I am thinking of having eventbridge to trigger the notification-generating lambda script whenever a new subscriber is added to topic, but not sure if its doable and also the fact that the existing subscribers will be notified again.
For step 4 I am completely clueless.
Thanks.
Solution 1:[1]
You can add a subscriber to a topic with boto3, see docs here: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sns.html#SNS.Client.subscribe And if you wont to send something out to that topic you publish to it, see docs here: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sns.html#SNS.Client.publish
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Erik Asplund |
