som*_*r81 2 python boto amazon-web-services amazon-sns
创建AWS SNS主题时:
a = conn.create_topic(topicname)
Run Code Online (Sandbox Code Playgroud)
或者已经创建了主题:
a = conn.get_all_topics()
Run Code Online (Sandbox Code Playgroud)
结果是:
{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'}}}
Run Code Online (Sandbox Code Playgroud)
问题是如何将主题的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])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4121 次 |
| 最近记录: |