UPD: Using proper pandas library for csv handling

This commit is contained in:
xpk 2024-04-23 18:18:30 +08:00
parent 5e56832f7e
commit 051b5267de
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
1 changed files with 10 additions and 3 deletions

View File

@ -2,15 +2,22 @@
import boto3
import pandas as pd
import csv
client = boto3.client('config')
resp = client.get_discovered_resource_counts()
print("ResourceType, ResourceId")
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=', ')
# 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)