Boto 仅删除 100 个 SNS 主题条目,并非全部
Boto is only deleting 100 entry of SNS Topic and Not all
我的帐户中有 700 个 SNS 主题。我正在使用 boto 删除所有这些。代码正在删除它们,但我看到每次只删除 100 个主题。我有 运行 代码 7 次删除所有 700 个主题。我要一次性全部删除
也手动尝试了 GUI 但同样的问题
def delete_topic(self, topic):
params = {'ContentType' : 'JSON',
'TopicArn' : topic}
response = self.make_request('DeleteTopic', params, '/', 'GET')
body = response.read()
if response.status == 200:
return json.loads(body)
else:
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
raise self.ResponseError(response.status, response.reason, body)
endpoint = boto.sqs.regioninfo.RegionInfo(name=region,endpoint='sns.'+str(region)+'.amazonaws.com')
sns = boto.connect_sns(aws_access_key_id=aKey, aws_secret_access_key=aSecret,region=endpoint)
topics = sns.get_all_topics()
dict_topic = topics[u'ListTopicsResponse']['ListTopicsResult']['Topics']
i=0
for key in dict_topic:
topic=topics[u'ListTopicsResponse']['ListTopicsResult']['Topics'][i]['TopicArn']
delete_topic(sns,topic)
print "Deleted the topic"+str(topic)
i = i + 1
你应该使用 next_token 参数,因为它是一个嵌套的字典分页:
get_all_topics(next_token=None)
Parameters: next_token (string) – Token returned by the previous call to this method.
你也可以检查这个post:
我的帐户中有 700 个 SNS 主题。我正在使用 boto 删除所有这些。代码正在删除它们,但我看到每次只删除 100 个主题。我有 运行 代码 7 次删除所有 700 个主题。我要一次性全部删除
也手动尝试了 GUI 但同样的问题
def delete_topic(self, topic):
params = {'ContentType' : 'JSON',
'TopicArn' : topic}
response = self.make_request('DeleteTopic', params, '/', 'GET')
body = response.read()
if response.status == 200:
return json.loads(body)
else:
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
raise self.ResponseError(response.status, response.reason, body)
endpoint = boto.sqs.regioninfo.RegionInfo(name=region,endpoint='sns.'+str(region)+'.amazonaws.com')
sns = boto.connect_sns(aws_access_key_id=aKey, aws_secret_access_key=aSecret,region=endpoint)
topics = sns.get_all_topics()
dict_topic = topics[u'ListTopicsResponse']['ListTopicsResult']['Topics']
i=0
for key in dict_topic:
topic=topics[u'ListTopicsResponse']['ListTopicsResult']['Topics'][i]['TopicArn']
delete_topic(sns,topic)
print "Deleted the topic"+str(topic)
i = i + 1
你应该使用 next_token 参数,因为它是一个嵌套的字典分页:
get_all_topics(next_token=None)
Parameters: next_token (string) – Token returned by the previous call to this method.
你也可以检查这个post: