Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paging snsClient.list_subscriptions() #10

Open
naomine-egawa opened this issue Oct 16, 2017 · 2 comments
Open

paging snsClient.list_subscriptions() #10

naomine-egawa opened this issue Oct 16, 2017 · 2 comments

Comments

@naomine-egawa
Copy link

naomine-egawa commented Oct 16, 2017

snsClient.list_subscriptions() seems to be returning 6 endpoints and paging 7+ to next page.
workarround as follow:

@@ -163,14 +163,17 @@ def lambda_handler(event, context):
 
             # If tasks are still running...
             if tasksRunning == 1:
-                response = snsClient.list_subscriptions()
-                for key in response['Subscriptions']:
-                    logger.info("Endpoint %s AND TopicArn %s and protocol %s ",key['Endpoint'], key['TopicArn'],
-                                                                                  key['Protocol'])
-                    if TopicArn == key['TopicArn'] and key['Protocol'] == 'lambda':
-                        logger.info("TopicArn match, publishToSNS function...")
-                        msgResponse = publishToSNS(message, key['TopicArn'])
-                        logger.debug("msgResponse %s and time is %s",msgResponse, datetime.datetime)
+                paginator = snsClient.get_paginator('list_subscriptions')
+                subscriptionListPages = paginator.paginate()
+                for subscriptionListResp in subscriptionListPages:
+                    #response = snsClient.list_subscriptions()
+                    for key in subscriptionListResp['Subscriptions']:
+                        logger.info("Endpoint %s AND TopicArn %s and protocol %s ",key['Endpoint'], key['TopicArn'],
+                                                                                      key['Protocol'])
+                        if TopicArn == key['TopicArn'] and key['Protocol'] == 'lambda':
+                            logger.info("TopicArn match, publishToSNS function...")
+                            msgResponse = publishToSNS(message, key['TopicArn'])
+                            logger.debug("msgResponse %s and time is %s",msgResponse, datetime.datetime)
             # If tasks are NOT running...
             elif tasksRunning == 0:
                 completeHook = 1

@fabianfett
Copy link

fabianfett commented Nov 1, 2017

Well, I think the client should use list_subscriptions_by_topic. There is no point in having this lambda retrieve all topics to filter then for its own topic.

http://boto3.readthedocs.io/en/latest/reference/services/sns.html#SNS.Client.list_subscriptions_by_topic

UPDATE: Oh, there is a pr for this already: #5. Why hasn't this been merged yet?

@jhmartin
Copy link

What is the point of fetching the list of subscriptions, when it already knows the TopicArn?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants