简体   繁体   中英

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:

  1. List all the SNS topics that I have currently
  2. Compare with a list/database/table to see if any topics are not in the existing list
  3. Create the topics
  4. Add subscribers into them
  5. Track their subscription status
  6. 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:

  1. import boto3 -> list_topics()
  2. 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()
  3. create_topic()
  4. ???
  5. list_subscriptions()/list_subscriptions_by_topic()
  6. ???

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM