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

2024-10-03 02:40:10 发布

您现在位置:Python中文网/ 问答频道 /正文

新手问题。我希望能做如下的事情:

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

连接工作正常,但最后一行返回错误“'unicode'object has no attribute'user'u id'”。在

我做了一个type(userList),它将类型报告为<;class'boto.jsonresponse.Element'>;,它不显示(?)待记录。使用普通的JSON解析似乎也不起作用。在

another source来看,意图似乎是这样一个操作的结果,应该被“pythonized”

不管怎样,我对boto还是个新手,所以我想有一些简单的方法可以做到这一点,我只是没有偶然发现过。在

谢谢!在


Tags: fromimportidgetallconnection事情users
1条回答
网友
1楼 · 发布于 2024-10-03 02:40:10

如果您希望输出由学生姓名A与标记2.1010.2之间的链接组成,则需要Map<String, List<Mark>>输出或使用当前的List<Student输出,该输出根据需要进行排序:

输出为List<Student>

return stds.stream()
  .sorted(Comparator.comparing(Student::getName))              // sort Students by name
  .map(student -> new Student(                                 // with sorted marks
     student.getName(),                                        // - same name
     student.getMarks().stream()                               // - sorted marks
       .sorted(Comparator.comparingDouble(Marks::getPoints))   //   comparing points
       .collect(Collectors.toCollection(LinkedHashSet::new)))) //   as LinkedHashSet
  .collect(Collectors.toList());                               // as List<Student>

[Student(name=A, marks=[Marks(points=2.1), Marks(points=10.2)]),

Student(name=B, marks=[Fooarks(points=13.0), Marks(points=15.0)]),

Student(name=C, marks=[Marks(points=7.0), Marks(points=20.0)])]


如果您觉得Map<String, List<Mark>>更合适,那么请注意对键进行排序的TreeMap实现:

return stds.stream()
    .collect(Collectors.toMap(                           // Map<String, List>
         Student::getName,                               // the key
         student -> student.getMarks().stream()          // the value (sorted)
             .sorted(Comparator.comparingDouble(
                     Marks::getPoints))
             .collect(Collectors.toList()),
         (o1, o2) -> o1,                                 // merge BinaryOperator
         TreeMap::new));                                 // requested implementation

{A=[Foo.Marks(points=2.1), Foo.Marks(points=10.2)],

B=[Foo.Marks(points=13.0), Foo.Marks(points=15.0)],

C=[Foo.Marks(points=7.0), Foo.Marks(points=20.0)]}

相关问题 更多 >