krz/aws-summary-report
Automated AWS summary reports, straight to your inbox.
clone: git clone https://gitbay.org/krz/aws-summary-report.git
main: sections/config.py · raw
1# config.py
2import boto3
3from tabulate import tabulate
4
5
6def get_section(config):
7 profile = config["aws"].get("profile")
8 region = config["aws"]["region"]
9 session = boto3.Session(
10 profile_name=profile if profile else None, region_name=region
11 )
12 client = session.client("config")
13
14 paginator = client.get_paginator("describe_compliance_by_resource")
15 page_iterator = paginator.paginate(ComplianceTypes=["NON_COMPLIANT"])
16
17 rows = []
18
19 for page in page_iterator:
20 for result in page.get("ComplianceByResources", []):
21 resource_type = result.get("ResourceType", "Unknown")
22 resource_id = result.get("ResourceId", "Unknown")
23 rows.append([resource_type, resource_id])
24
25 if not rows:
26 return "AWS Config Non-Compliance:\nAll resources are compliant."
27
28 table = tabulate(
29 rows, headers=["Resource Type", "Resource ID"], tablefmt="simple_grid"
30 )
31 lines = [
32 "AWS Config Non-Compliant Resources:",
33 f"[https://{config['aws'].get('region')}.console.aws.amazon.com/config/home#/resources?complianceType=NON_COMPLIANT]",
34 table,
35 ]
36
37 return "\n".join(lines)