2024-03-06 09:49:46 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
|
|
import boto3
|
2024-04-23 18:18:30 +08:00
|
|
|
import pandas as pd
|
|
|
|
import csv
|
2024-03-06 09:49:46 +08:00
|
|
|
|
|
|
|
client = boto3.client('config')
|
|
|
|
resp = client.get_discovered_resource_counts()
|
2024-04-23 18:18:30 +08:00
|
|
|
results = []
|
|
|
|
# print("ResourceType, ResourceId")
|
2024-03-06 09:49:46 +08:00
|
|
|
for item in resp['resourceCounts']:
|
2024-04-23 17:37:51 +08:00
|
|
|
if item['resourceType'] == "AWS::Config::ResourceCompliance":
|
|
|
|
continue
|
2024-03-06 09:49:46 +08:00
|
|
|
reslist = client.list_discovered_resources(resourceType=item['resourceType'])
|
|
|
|
|
2024-04-23 17:37:51 +08:00
|
|
|
for res in reslist['resourceIdentifiers']:
|
2024-04-23 18:18:30 +08:00
|
|
|
# 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)
|