Getting Information about IAM Users - AWS SDK for Ruby

Getting Information about IAM Users

The following example lists the groups, policies, and access key IDs of the IAM users in the us-west-2 region. If there are more than 100 users, iam.list_users.IsTruncated is true and iam.list_users.Marker contains a value you can use to get information about additional users. See the Aws::IAM::Client.list_users topic for further information.

require 'aws-sdk-iam' # v2: require 'aws-sdk' iam = 'us-west-2') iam.list_users.users.each do |user| name = user.user_name puts "For user #{name}" puts " In groups:" iam.list_groups_for_user({user_name: name}).groups.each do |group| puts " #{group.group_name}" end puts " Policies:" iam.list_user_policies({user_name: name}).policy_names.each do |policy| puts " #{policy}" end puts " Access keys:" iam.list_access_keys({user_name: name}).access_key_metadata.each do |key| puts " #{key.access_key_id}" end end