コード例 #1
0
def ec2_report(pth):
    for account in profiles.profile_list():
        print('Current account: ' + account)
        for region in regions.region_list():
            print('Current region: ' + region)
            session = boto3.Session(profile_name=account)
            client = session.client('ec2', region_name=region)
            response = client.describe_instances()
            #
            for r in response['Reservations']:

                for i in r['Instances']:
                    try:
                        for tag in i['Tags']:

                            if tag['Key'] == 'Name':
                                instance_name = tag['Value']
                            else:
                                instance_name = 'None'
                            if tag['Key'] == 'Site':
                                instance_site = tag['Value']
                            else:
                                instance_site = 'None'

                        with open(pth, "a") as myfile:
                            myfile.write(account + ',' + region + ',' +
                                         i['InstanceId'] + ',' +
                                         instance_name + ',' + instance_site +
                                         ',' + str(i.get('PublicIpAddress')) +
                                         ',' + str(i.get('PrivateIpAddress')) +
                                         '\n')
                    except Exception, msg:
                        print(msg)
コード例 #2
0
def iam_report(pth):
    for account in profiles.profile_list():
        print('Current account: ' + account)
        session = boto3.Session(profile_name=account)
        client = session.client('iam')
        response = client.list_users()

        for r in response['Users']:
            try:
                with open(pth, "a") as myfile:
                    myfile.write(account + ',' + r['UserName'] + ',' +
                                 str(r['CreateDate'].date()) + '\n')
            except Exception, msg:
                print(str(msg))
コード例 #3
0
def lb_report(pth):
    for account in profiles.profile_list():
        print('Current account: ' + account)
        for region in regions.region_list():
            print('Current region: ' + region)
            session = boto3.Session(profile_name=account)
            client = session.client('elb', region_name=region)
            response = client.describe_load_balancers()
            # print(str(response))
            for r in response['LoadBalancerDescriptions']:
                try:
                    with open(pth, "a") as myfile:
                        myfile.write(account + ',' + region + ',' +
                                     r['CanonicalHostedZoneName'] + '\n')
                except Exception, msg:
                    print(msg)
コード例 #4
0
def bucket_report(pth):
    for account in profiles.profile_list():
        print('Current account: ' + account)
        for region in regions.region_list():
            print('Current region: ' + region)
            session = boto3.Session(profile_name=account)
            client = session.client('s3', region_name=region)
            response = client.list_buckets()

            # print (str(response))

            for r in response['Buckets']:
                try:
                    with open(pth, "a") as myfile:
                        myfile.write(account + ',' + region + ',' + r['Name'] +
                                     '\n')
                except Exception, msg:
                    print(str(msg))
コード例 #5
0
def rds_report(pth):
    for account in profiles.profile_list():
        print('Current account: ' + account)
        for region in regions.region_list():
            print('Current region: ' + region)
            session = boto3.Session(profile_name=account)
            client = session.client('rds', region_name=region)
            response = client.describe_db_instances()

            # print str(response)

            for r in response['DBInstances']:
                try:
                    with open(pth, "a") as myfile:
                        myfile.write(account + ',' + region + ',' +
                                     r['Endpoint']['Address'] + ',' +
                                     r['LicenseModel'] + '\n')
                except Exception, msg:
                    print(str(msg))