I'm trying to verify if a topic exists based on topic name.
Do you know if this is possible?
For example I want to verify if topic with name "test" already exist.
Below is what I'm trying but doesn't work because topicsList contains topicArns and not topicNames...
topics = sns.get_all_topics()
topicsList = topics['ListTopicsResponse']['ListTopicsResult'['Topics']
if "test" in topicsList:
print("true")
RustyShackleford :
This code will work if you have more than 100 topics\n\ndef get_topic(token=None):\n topics = self.sns.get_all_topics(token)\n next_token = topics['ListTopicsResponse']['ListTopicsResult']['NextToken']\n topic_list = topics['ListTopicsResponse']['ListTopicsResult']['Topics']\n for topic in topic_list:\n if \"your_topic_name\" in topic['TopicArn'].split(':')[5]:\n return topic['TopicArn']\n else:\n if next_token:\n get_topic(next_token)\n else:\n return None\n",
2015-08-14T22:31:34
panchicore :
What if you try to catch An error occurred (NotFound) when calling the GetTopicAttributes operation: Topic does not exist exception?\n\nfrom botocore.exceptions import ClientError\n\ntopic_arn = \"arn:aws:sns:us-east-1:999999999:neverFound\"\n\ntry:\n response = client.get_topic_attributes(\n TopicArn=topic_arn\n )\n print \"Exists\"\nexcept ClientError as e:\n # Validate if is this:\n # An error occurred (NotFound) when calling the GetTopicAttributes operation: Topic does not exist\n print \"Does not exists\"\n",
2017-01-31T10:31:23