2024-03-06 09:49:46 +08:00
|
|
|
#!/usr/bin/env python3
|
2024-04-23 23:13:27 +08:00
|
|
|
|
2024-03-06 09:49:46 +08:00
|
|
|
|
|
|
|
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 23:13:06 +08:00
|
|
|
# print('totalDiscoveredResources', resp['totalDiscoveredResources'], sep=": ")
|
2024-04-23 18:18:30 +08:00
|
|
|
results = []
|
2024-03-06 09:49:46 +08:00
|
|
|
for item in resp['resourceCounts']:
|
2024-04-24 16:06:17 +08:00
|
|
|
paginator = client.get_paginator('list_discovered_resources')
|
|
|
|
page_iterator = paginator.paginate(resourceType=item['resourceType'])
|
|
|
|
for page in page_iterator:
|
|
|
|
for res in page['resourceIdentifiers']:
|
2024-04-23 23:13:06 +08:00
|
|
|
if item['resourceType'] in [
|
|
|
|
"AWS::Config::ResourceCompliance",
|
|
|
|
"AWS::Backup::RecoveryPoint",
|
|
|
|
"AWS::RDS::DBSnapshot",
|
|
|
|
"AWS::SSM::ManagedInstanceInventory",
|
|
|
|
"AWS::SSM::AssociationCompliance",
|
2024-04-23 23:19:45 +08:00
|
|
|
"AWS::SSM::PatchCompliance",
|
2024-04-23 23:13:06 +08:00
|
|
|
"AWS::IAM::Policy"
|
|
|
|
]:
|
|
|
|
continue
|
2024-04-23 23:19:45 +08:00
|
|
|
preferResName = res.get('resourceName', res.get('resourceId'))
|
|
|
|
results += [[item['resourceType'], preferResName]]
|
2024-04-23 18:18:30 +08:00
|
|
|
|
|
|
|
df = pd.DataFrame(results, columns=['ResourceType', 'ResourceId'])
|
2024-04-23 23:13:06 +08:00
|
|
|
# print(df)
|
|
|
|
print(df.to_csv(index=False, quoting=csv.QUOTE_NONNUMERIC))
|