title: How can we fetch IAM users, their groups and policies?
body: <p>I need to fetch all the aws user's, their corresponding groups, policies and then if mfa is activated for them or not. Can anyone tell me how it can be done via aws cli or boto.</p>
  
  <p>I have a script that fetches out just the all user's in aws.</p>
  
  <pre><code>  import boto3
      from boto3 import *
      import argparse
  
      access_key = ''
      secret_key = ''
  
      def get_iam_uses_list():
      client =  boto3.client('iam',
                  aws_access_key_id=access_key,
                  aws_secret_access_key=secret_key)
         my_list=list()
         iam_all_users = client.list_users(MaxItems=200)
         for user in iam_all_users['Users']:
          my_list.append(user['UserName'])
  #
  
      for i in my_list:
          print i
  
  #    print "read complete"
  #
  #    for i in my_list:
  #        iam_user_policy=client.list_attached_user_policies(UserName=i)
  #        for policy in iam_user_policy['AttachedPolicies']:
  #               print "%s \t %s" %(i, policy['PolicyName'])
  
  def main():
      parser = argparse.ArgumentParser()
      parser.add_argument('access_key', help='Access Key');
      parser.add_argument('secret_key', help='Secret Key');
      args = parser.parse_args()
      global access_key
      global secret_key
      access_key = args.access_key
      secret_key = args.secret_key
  get_iam_uses_list()
  
  if  __name__ =='__main__':main()
  </code></pre>