code-dumps/aws/aws-inventory-from-awsconfig.py

23 lines
720 B
Python
Raw Normal View History

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