简体   繁体   English

使用boto(AWS Python),如何获取IAM用户列表?

[英]Using boto (AWS Python), how do I get a list of IAM users?

Newbie question. 新手问题。 I'm expecting to be able to do something like the following: 我期望能够执行以下操作:

import boto
from boto.iam.connection import IAMConnection
cfn = IAMConnection()
cfn.get_all_users()
for user in userList:
    print user.user_id

The connection works fine, but the last line returns the error "'unicode' object has no attribute 'user_id'". 连接工作正常,但最后一行返回错误“'unicode'对象没有属性'user_id'”。

I did a type(userList) and it reported the type as <class 'boto.jsonresponse.Element'>, which doesn't appear (?) to be documented. 我做了一个type(userList) ,它把该类型报告为<class'boto.jsonresponse.Element'>,它没有出现(?)待记录。 Using normal JSON parsing doesn't appear to work either. 使用普通的JSON解析似乎也不起作用。

From another source , it looks as if the intent is the results of an operation like this are supposed to be "pythonized." 另一个来源看 ,它的意图似乎是应该将这种操作的结果“ pythonized”。

Anyway, I'm pretty new to boto, so I assume there's some simple way to do this that I just haven't stumbled across. 无论如何,我对boto还是很陌生,所以我认为有一些简单的方法可以做到,而我只是没有偶然发现。

Thx! 谢谢!

For some of the older AWS services, boto takes the XML responses from the service and turns them into nice Python objects. 对于某些较旧的AWS服务,boto从服务中获取XML响应并将其转换为漂亮的Python对象。 For others, it takes the XML response and transliterates it directly into native Python data structures. 对于其他人,它接受XML响应并将其直接音译为本地Python数据结构。 The boto.iam module is of the latter form. boto.iam模块是后一种形式。 So, the actual data returned by get_all_users() looks like this: 因此, get_all_users()返回的实际数据如下所示:

{u'list_users_response':
  {u'response_metadata': {u'request_id': u'8d694cbd-93ec-11e3-8276-993b3edf6dba'},   
   u'list_users_result': {u'users': 
     [{u'path': u'/', u'create_date': u'2014-01-21T17:19:45Z', u'user_id': 
       u'<userid>', u'arn': u'<arn>', u'user_name': u'foo'},
      {...next user...}
     ]
  }
}

So, all of the data you want is there, it's just a bit difficult to find. 因此,您想要的所有数据都在那里,很难找到。 The boto.jsonresponse.Element object returned does give you a little help. 返回的boto.jsonresponse.Element对象确实为您提供了一些帮助。 You can actually do something like this: 您实际上可以执行以下操作:

data = cfn.get_all_users()
for user in data.user:
    print(user['user_name'])

but for the most part you just have to dig around in the data returned to find what you are looking for. 但在大多数情况下,您只需要在返回的数据中进行挖掘,即可找到所需的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 boto 在 AWS iam 中获取用户的权限或组详细信息 - How to get the permission or group details of the users in AWS iam using boto 如何使用 BOTO python 在 AWS 中获取实例的公共 dns - How do i get the public dns of an instance in AWS using BOTO python 如何使用 python boto3 将新角色权限附加到 aws 中的 iam_role? - How to attach new role permissions to iam_role in aws using python boto3? 使用boto3,如何检查AWS IAM用户是否具有密码? - Using boto3, how to check if AWS IAM user has password? AWS Python IAM API-如何以编程方式获取AWS IAM特权? - AWS Python IAM API - how to get AWS IAM privileges programmatically? 如何使用 boto3 获取所有 AWS AMI 的列表? - How to get the list of all AWS AMIs using boto3? 如何使用 boto3 列出附加到 IAM 角色的所有资源? - How can I list the all the resources attached to a IAM role using boto3? 如何在 python 中使用 boto3 访问 AWS 参数存储中的参数描述? - How do I access a parameter's description in AWS parameter store, using boto3 in python? 如何使用Boto启动/停止AWS RDS实例? - How do I Start/Stop AWS RDS Instances using Boto? Python-如何使用Django获取Facebook用户的好友列表,状态更新等? - Python- How do I get a Facebook users friend list, status updates, etc. using Django?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM