创建 AWS SNS 主题时:
a = conn.create_topic(topicname)
或获取已创建的主题:
a = conn.get_all_topics()
结果是:
{u'CreateTopicResponse': {u'ResponseMetadata': {u'RequestId': u'42b46710-degf-52e6-7d86-2ahc8e1c738c'}, u'CreateTopicResult': {u'TopicArn': u'arn:aws:sns:eu-west-1:467741034465:exampletopic'}}}
问题是如何获取主题的 ARN 作为字符串:arn:aws:sns:eu-west-1:467741034465:exampletopic
?
import boto
def get_account_id():
# suggested by https://groups.google.com/forum/#!topic/boto-users/QhASXlNBm40
return boto.connect_iam().get_user().arn.split(':')[4]
def topic_arn_from_name(self, region, name):
return ":".join(["arn", "aws", "sns", region, get_account_id(), name])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)