创建 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])
关于python - Boto - AWS SNS 如何提取主题的 ARN 编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26656286/