通过 java aws sdk 获取 IAM 用户列表

Get IAM users list by java aws sdk

想要获取所有使用 sdk aws 的 IAM 用户的列表 java。 Class 我们使用的是 AmazonIdentityManagementClient,使用的方法是 listuser()。 API 文档建议传递参数 MaxItem 和 Marker。而方法不识别参数。谁能在这里建议如何进行分页。

    AmazonIdentityManagementClient amazonidentitymanagmentclient = new AmazonIdentityManagementClient();

    ListUsersResult listuserresult = new ListUsersResult();

 try {

       listuserresult=amazonidentitymanagmentclient.listUsers();

       List<User> listuser = new ArrayList<User>();

       listuser = listuserresult.getUsers() //need to pass maxitems,marker here
     }


     } catch (Exception e) {
         return null;
     }

您需要使用

ListUsersResult listUsers(ListUsersRequest listUsersRequest)
                          throws AmazonServiceException,
                                 AmazonClientException

使用标记功能。
您可以在 ListUsersRequest . You need to get the marker from the results ( ListUsersResult ) of previous call of the listusers. The ListUsersResult has a method getMarker which can be used to get the marker to be used for next call. Then use the object ListUsesrsRequest. set the marker with the value got from getMarker and then call this listusers 中设置标记。在循环中执行此操作,直到 ListUsersResults 中的 isTruncated 方法指示没有更多元素到 return。如果您不设置 maxitem,默认情况下它将 return 100 项根据文档。您可以在 ListUsersRequest 中根据您希望在页面中显示的数量将其设置为不同的值。