博托 - AWS SNS如何提取主题的ARN号码 [英] Boto - AWS SNS how to extract topic's ARN number

查看:835
本文介绍了博托 - AWS SNS如何提取主题的ARN号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建AWS SNS主题:

When creating a AWS SNS topic:

a = conn.create_topic(topicname)

或获取已创建的主题:

or getting the topic already created:

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:欧盟 - 西1:467741034465:exampletopic

推荐答案

当你创建一个新的话题,博托返回一个Python字典,上面描述的数据。为了获得主题ARN作为一个字符串,只需引用该密钥在这样的词典:

When you create a new topic, boto returns a Python dictionary with the data you describe above. To get the topic ARN as a string, simply reference that key in the dictionary like this:

a = conn.create_topic(topicname)
a_arn = a['CreateTopicResponse']['CreateTopicResult']['TopicArn']

这有点笨重,但它的工作原理。

it's kind of clunky but it works.

list_topics 调用返回一个不同的结构,基本上是这样的:

The list_topics call returns a different structure, basically like this:

{u'ListTopicsResponse':
  {u'ListTopicsResult':
    {u'NextToken': None,
     u'Topics': [
      {u'TopicArn': u'arn:aws:sns:us-east-1:467741034465:exampletopic'},
      {u'TopicArn': u'arn:aws:sns:us-east-1:467741034465:footopic'}
     ]
    },
  u'ResponseMetadata': {u'RequestId': u'aef821f6-d595-55e1-af14-6d3a8064536a'}}}

在这种情况下,如果你想获得你会用第一个主题的ARN:

In this case, if you wanted to get the ARN of the first topic you would use:

a = conn.list_topics()
a_arn = a['ListTopicsResponse']['ListTopicsResult']['Topics'][0]['TopicArn']

这篇关于博托 - AWS SNS如何提取主题的ARN号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆