#!/usr/bin/env python3 import boto3 import pandas as pd import csv client = boto3.client('config') resp = client.get_discovered_resource_counts() results = [] # print("ResourceType, ResourceId") for item in resp['resourceCounts']: if item['resourceType'] == "AWS::Config::ResourceCompliance": continue reslist = client.list_discovered_resources(resourceType=item['resourceType']) for res in reslist['resourceIdentifiers']: # print(item['resourceType'], res['resourceId'], sep=', ') results += [[item['resourceType'], res['resourceId']]] df = pd.DataFrame(results, columns=['ResourceType', 'ResourceId']) print(df.to_csv(index=False,quoting=csv.QUOTE_NONNUMERIC)) # print(results)