#!/usr/bin/env python3 import boto3 import pandas as pd import csv client = boto3.client('config') resp = client.get_discovered_resource_counts() # print('totalDiscoveredResources', resp['totalDiscoveredResources'], sep=": ") results = [] for item in resp['resourceCounts']: reslist = client.list_discovered_resources(resourceType=item['resourceType']) nextToken = reslist.get('nextToken') while True: for res in reslist['resourceIdentifiers']: if item['resourceType'] in [ "AWS::Config::ResourceCompliance", "AWS::Backup::RecoveryPoint", "AWS::RDS::DBSnapshot", "AWS::SSM::ManagedInstanceInventory", "AWS::SSM::AssociationCompliance", "AWS::SSM::PatchCompliance", "AWS::IAM::Policy" ]: continue preferResName = res.get('resourceName', res.get('resourceId')) results += [[item['resourceType'], preferResName]] if nextToken is None: break reslist = client.list_discovered_resources(resourceType=item['resourceType'], nextToken=nextToken) nextToken = reslist.get('nextToken') df = pd.DataFrame(results, columns=['ResourceType', 'ResourceId']) # print(df) print(df.to_csv(index=False, quoting=csv.QUOTE_NONNUMERIC))