Reputation: 41
I need to unsubscribe endpoints from topics during the deletion. I see that when I delete an endpoint I still have a reference(to just deleted endpoint) in topic subscriptions. How am I supposed to remove it? I see that SnsClient in java has this method
snsClient.unsubscribe("sunbscription-arn");
But I don't keep subscription arns in my db. Is there any way to avoid keeping these arns?
Upvotes: 2
Views: 2442
Reputation: 391
I tried to unsubscribe endpoint from topic by following python code (use boto):
def _unsubscribe_from_topic(topic_arn, endpoint):
conn = connect_to_region('your_region_name','AWS_ACCESS_KEY', 'AWS_SECRET_KEY')
r = conn.get_all_subscriptions_by_topic(topic_arn)
for i in r.get('ListSubscriptionsByTopicResponse')\
.get('ListSubscriptionsByTopicResult')\
.get('Subscriptions'):
if i.get('Endpoint') == endpoint:
subscription = i.get('SubscriptionArn')
conn.unsubscribe(subscription)
return True
return False
reference: http://boto.readthedocs.org/en/latest/ref/sns.html
Upvotes: 3