aws-finops-auditor 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,138 @@
1
+ Metadata-Version: 2.4
2
+ Name: aws-finops-auditor
3
+ Version: 1.0.0
4
+ Summary: Read-only AWS FinOps CLI auditor for identifying idle compute, orphaned storage, and unattached network waste.
5
+ Author: Aisser Rodriguez
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Ace-FinOps-Enterprise/aws-finops-auditor
8
+ Project-URL: Repository, https://github.com/Ace-FinOps-Enterprise/aws-finops-auditor
9
+ Project-URL: Practitioner & Enterprise Tiers, https://aisser.gumroad.com/l/krgac
10
+ Keywords: aws,finops,cloud-cost,cost-optimization,devops,cli
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: System Administrators
14
+ Classifier: Topic :: System :: Systems Administration
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: boto3>=1.28.0
23
+ Requires-Dist: pandas>=2.0.0
24
+ Provides-Extra: enterprise
25
+ Requires-Dist: fpdf>=1.7.2; extra == "enterprise"
26
+ Requires-Dist: requests>=2.31.0; extra == "enterprise"
27
+
28
+ # AWS Cloud Cost Auditor & FinOps Toolkit
29
+
30
+ A zero-agent, production-grade CLI suite designed to audit AWS infrastructure for orphaned resources, calculate monthly financial drag, synthesize remediation bash scripts, and generate branded executive PDF showbacks.
31
+
32
+ ---
33
+
34
+ ## Prerequisites
35
+
36
+ - **Python 3.10+**
37
+ - **AWS CLI** configured with appropriate permissions (`aws configure` or standard AWS environment variables: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION`).
38
+
39
+ ---
40
+
41
+ ## Installation
42
+
43
+ Extract your purchased archive, navigate into the directory, and install dependencies:
44
+
45
+ ```bash
46
+ pip install -r requirements.txt
47
+ ```
48
+
49
+ ---
50
+
51
+ ## 1. Practitioner Quickstart (Single-Account Audits)
52
+
53
+ > *Included in Practitioner & Agency tiers (`infrastructure_auditor.py`)*
54
+
55
+ Audit the active AWS account configured in your local environment.
56
+
57
+ ### Run Audit Against Live AWS Infrastructure
58
+ ```bash
59
+ python infrastructure_auditor.py --compliance --remediate
60
+ ```
61
+
62
+ ### Run in Demo / Offline Mode (Using Sample Dataset)
63
+ ```bash
64
+ python infrastructure_auditor.py --file sample_aws_data.csv --compliance --remediate
65
+ ```
66
+
67
+ ### Outputs Generated:
68
+ - **Terminal Summary:** Categorized breakdown of orphaned EBS volumes, low-utilization compute, and unassociated Elastic IPs.
69
+ - **`compliance_audit_export.csv`:** Full resource inventory with showback cost tags and compliance control mappings (SOC2 CC6.6, ISO27001 A.10.1.1).
70
+ - **`remediate_anomalies.sh`:** Ready-to-review bash script with safe CLI commands to purge waste.
71
+
72
+ ---
73
+
74
+ ## 2. Enterprise & Agency Quickstart (Multi-Account AWS Organizations)
75
+
76
+ > *Included in the Consultancy & Agency Pack (`enterprise_audit.py`)*
77
+
78
+ Scan multiple member accounts across an entire AWS Organization via STS role assumption and generate executive PDF reports.
79
+
80
+ ### Cross-Account IAM Role Setup
81
+ Deploy `org-access-role.yaml` via **AWS CloudFormation StackSets** across your target member accounts:
82
+ - Default Role Name: `OrganizationAccountAccessRole`
83
+ - Trust Relationship: Your primary management/auditing account ID.
84
+
85
+ ### Run Full Multi-Account Audit & Executive PDF Generation
86
+ ```bash
87
+ python enterprise_audit.py --license-key YOUR_GUMROAD_KEY --report --remediate
88
+ ```
89
+
90
+ ### Advanced Enterprise CLI Flags
91
+ | Flag | Description | Default |
92
+ | :--- | :--- | :--- |
93
+ | `--license-key` | Gumroad enterprise license key for verification | *Required* |
94
+ | `--report` | Compiles client-ready executive PDF report | `False` |
95
+ | `--report-out` | Custom output file path for the PDF deliverable | `AWS_FinOps_Executive_Report.pdf` |
96
+ | `--remediate` | Generates `remediate_anomalies.sh` purge script | `False` |
97
+ | `--org-id` | Custom company/client name for PDF header branding | `AWS Organization Root` |
98
+ | `--regions` | Comma-separated list of AWS regions to scan | `us-east-1,us-east-2,us-west-2` |
99
+ | `--role-name` | Cross-account IAM role to assume via STS | `OrganizationAccountAccessRole` |
100
+ | `--demo` | Populates report from `sample_aws_data.csv` if live accounts show $0 waste | `False` |
101
+
102
+ ### Example: Multi-Region Scan with Custom Client Branding
103
+ ```bash
104
+ python enterprise_audit.py \
105
+ --license-key YOUR_GUMROAD_KEY \
106
+ --org-id "Acme Corp Infrastructure" \
107
+ --regions "us-east-1,us-west-2,eu-west-1" \
108
+ --report \
109
+ --report-out "Acme_FinOps_Q4_Audit.pdf" \
110
+ --remediate
111
+ ```
112
+
113
+ ---
114
+
115
+ ## 3. Executing Remediation Safely
116
+
117
+ Every audit that includes `--remediate` generates an idempotent bash script (`remediate_anomalies.sh`) with `set -euo pipefail` safety controls:
118
+
119
+ 1. **Inspect before executing:**
120
+ ```bash
121
+ cat remediate_anomalies.sh
122
+ # On Windows PowerShell:
123
+ Get-Content remediate_anomalies.sh
124
+ ```
125
+ 2. **Execute remediation purge:**
126
+ ```bash
127
+ chmod +x remediate_anomalies.sh
128
+ ./remediate_anomalies.sh
129
+ ```
130
+
131
+ *Non-destructive actions (like upgrading deprecated RDS engines) are prefixed with `#` as operational warnings and require manual review.*
132
+
133
+ ---
134
+
135
+ ## Support & Upgrades
136
+
137
+ - **Commercial Licenses & Add-ons:** [Gumroad Product Portal](https://aisser.gumroad.com/l/krgac)
138
+ - **Issues & Support:** Contact support via your Gumroad receipt portal or primary vendor email.
@@ -0,0 +1,111 @@
1
+ # AWS Cloud Cost Auditor & FinOps Toolkit
2
+
3
+ A zero-agent, production-grade CLI suite designed to audit AWS infrastructure for orphaned resources, calculate monthly financial drag, synthesize remediation bash scripts, and generate branded executive PDF showbacks.
4
+
5
+ ---
6
+
7
+ ## Prerequisites
8
+
9
+ - **Python 3.10+**
10
+ - **AWS CLI** configured with appropriate permissions (`aws configure` or standard AWS environment variables: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION`).
11
+
12
+ ---
13
+
14
+ ## Installation
15
+
16
+ Extract your purchased archive, navigate into the directory, and install dependencies:
17
+
18
+ ```bash
19
+ pip install -r requirements.txt
20
+ ```
21
+
22
+ ---
23
+
24
+ ## 1. Practitioner Quickstart (Single-Account Audits)
25
+
26
+ > *Included in Practitioner & Agency tiers (`infrastructure_auditor.py`)*
27
+
28
+ Audit the active AWS account configured in your local environment.
29
+
30
+ ### Run Audit Against Live AWS Infrastructure
31
+ ```bash
32
+ python infrastructure_auditor.py --compliance --remediate
33
+ ```
34
+
35
+ ### Run in Demo / Offline Mode (Using Sample Dataset)
36
+ ```bash
37
+ python infrastructure_auditor.py --file sample_aws_data.csv --compliance --remediate
38
+ ```
39
+
40
+ ### Outputs Generated:
41
+ - **Terminal Summary:** Categorized breakdown of orphaned EBS volumes, low-utilization compute, and unassociated Elastic IPs.
42
+ - **`compliance_audit_export.csv`:** Full resource inventory with showback cost tags and compliance control mappings (SOC2 CC6.6, ISO27001 A.10.1.1).
43
+ - **`remediate_anomalies.sh`:** Ready-to-review bash script with safe CLI commands to purge waste.
44
+
45
+ ---
46
+
47
+ ## 2. Enterprise & Agency Quickstart (Multi-Account AWS Organizations)
48
+
49
+ > *Included in the Consultancy & Agency Pack (`enterprise_audit.py`)*
50
+
51
+ Scan multiple member accounts across an entire AWS Organization via STS role assumption and generate executive PDF reports.
52
+
53
+ ### Cross-Account IAM Role Setup
54
+ Deploy `org-access-role.yaml` via **AWS CloudFormation StackSets** across your target member accounts:
55
+ - Default Role Name: `OrganizationAccountAccessRole`
56
+ - Trust Relationship: Your primary management/auditing account ID.
57
+
58
+ ### Run Full Multi-Account Audit & Executive PDF Generation
59
+ ```bash
60
+ python enterprise_audit.py --license-key YOUR_GUMROAD_KEY --report --remediate
61
+ ```
62
+
63
+ ### Advanced Enterprise CLI Flags
64
+ | Flag | Description | Default |
65
+ | :--- | :--- | :--- |
66
+ | `--license-key` | Gumroad enterprise license key for verification | *Required* |
67
+ | `--report` | Compiles client-ready executive PDF report | `False` |
68
+ | `--report-out` | Custom output file path for the PDF deliverable | `AWS_FinOps_Executive_Report.pdf` |
69
+ | `--remediate` | Generates `remediate_anomalies.sh` purge script | `False` |
70
+ | `--org-id` | Custom company/client name for PDF header branding | `AWS Organization Root` |
71
+ | `--regions` | Comma-separated list of AWS regions to scan | `us-east-1,us-east-2,us-west-2` |
72
+ | `--role-name` | Cross-account IAM role to assume via STS | `OrganizationAccountAccessRole` |
73
+ | `--demo` | Populates report from `sample_aws_data.csv` if live accounts show $0 waste | `False` |
74
+
75
+ ### Example: Multi-Region Scan with Custom Client Branding
76
+ ```bash
77
+ python enterprise_audit.py \
78
+ --license-key YOUR_GUMROAD_KEY \
79
+ --org-id "Acme Corp Infrastructure" \
80
+ --regions "us-east-1,us-west-2,eu-west-1" \
81
+ --report \
82
+ --report-out "Acme_FinOps_Q4_Audit.pdf" \
83
+ --remediate
84
+ ```
85
+
86
+ ---
87
+
88
+ ## 3. Executing Remediation Safely
89
+
90
+ Every audit that includes `--remediate` generates an idempotent bash script (`remediate_anomalies.sh`) with `set -euo pipefail` safety controls:
91
+
92
+ 1. **Inspect before executing:**
93
+ ```bash
94
+ cat remediate_anomalies.sh
95
+ # On Windows PowerShell:
96
+ Get-Content remediate_anomalies.sh
97
+ ```
98
+ 2. **Execute remediation purge:**
99
+ ```bash
100
+ chmod +x remediate_anomalies.sh
101
+ ./remediate_anomalies.sh
102
+ ```
103
+
104
+ *Non-destructive actions (like upgrading deprecated RDS engines) are prefixed with `#` as operational warnings and require manual review.*
105
+
106
+ ---
107
+
108
+ ## Support & Upgrades
109
+
110
+ - **Commercial Licenses & Add-ons:** [Gumroad Product Portal](https://aisser.gumroad.com/l/krgac)
111
+ - **Issues & Support:** Contact support via your Gumroad receipt portal or primary vendor email.
@@ -0,0 +1,138 @@
1
+ Metadata-Version: 2.4
2
+ Name: aws-finops-auditor
3
+ Version: 1.0.0
4
+ Summary: Read-only AWS FinOps CLI auditor for identifying idle compute, orphaned storage, and unattached network waste.
5
+ Author: Aisser Rodriguez
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Ace-FinOps-Enterprise/aws-finops-auditor
8
+ Project-URL: Repository, https://github.com/Ace-FinOps-Enterprise/aws-finops-auditor
9
+ Project-URL: Practitioner & Enterprise Tiers, https://aisser.gumroad.com/l/krgac
10
+ Keywords: aws,finops,cloud-cost,cost-optimization,devops,cli
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: System Administrators
14
+ Classifier: Topic :: System :: Systems Administration
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: boto3>=1.28.0
23
+ Requires-Dist: pandas>=2.0.0
24
+ Provides-Extra: enterprise
25
+ Requires-Dist: fpdf>=1.7.2; extra == "enterprise"
26
+ Requires-Dist: requests>=2.31.0; extra == "enterprise"
27
+
28
+ # AWS Cloud Cost Auditor & FinOps Toolkit
29
+
30
+ A zero-agent, production-grade CLI suite designed to audit AWS infrastructure for orphaned resources, calculate monthly financial drag, synthesize remediation bash scripts, and generate branded executive PDF showbacks.
31
+
32
+ ---
33
+
34
+ ## Prerequisites
35
+
36
+ - **Python 3.10+**
37
+ - **AWS CLI** configured with appropriate permissions (`aws configure` or standard AWS environment variables: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION`).
38
+
39
+ ---
40
+
41
+ ## Installation
42
+
43
+ Extract your purchased archive, navigate into the directory, and install dependencies:
44
+
45
+ ```bash
46
+ pip install -r requirements.txt
47
+ ```
48
+
49
+ ---
50
+
51
+ ## 1. Practitioner Quickstart (Single-Account Audits)
52
+
53
+ > *Included in Practitioner & Agency tiers (`infrastructure_auditor.py`)*
54
+
55
+ Audit the active AWS account configured in your local environment.
56
+
57
+ ### Run Audit Against Live AWS Infrastructure
58
+ ```bash
59
+ python infrastructure_auditor.py --compliance --remediate
60
+ ```
61
+
62
+ ### Run in Demo / Offline Mode (Using Sample Dataset)
63
+ ```bash
64
+ python infrastructure_auditor.py --file sample_aws_data.csv --compliance --remediate
65
+ ```
66
+
67
+ ### Outputs Generated:
68
+ - **Terminal Summary:** Categorized breakdown of orphaned EBS volumes, low-utilization compute, and unassociated Elastic IPs.
69
+ - **`compliance_audit_export.csv`:** Full resource inventory with showback cost tags and compliance control mappings (SOC2 CC6.6, ISO27001 A.10.1.1).
70
+ - **`remediate_anomalies.sh`:** Ready-to-review bash script with safe CLI commands to purge waste.
71
+
72
+ ---
73
+
74
+ ## 2. Enterprise & Agency Quickstart (Multi-Account AWS Organizations)
75
+
76
+ > *Included in the Consultancy & Agency Pack (`enterprise_audit.py`)*
77
+
78
+ Scan multiple member accounts across an entire AWS Organization via STS role assumption and generate executive PDF reports.
79
+
80
+ ### Cross-Account IAM Role Setup
81
+ Deploy `org-access-role.yaml` via **AWS CloudFormation StackSets** across your target member accounts:
82
+ - Default Role Name: `OrganizationAccountAccessRole`
83
+ - Trust Relationship: Your primary management/auditing account ID.
84
+
85
+ ### Run Full Multi-Account Audit & Executive PDF Generation
86
+ ```bash
87
+ python enterprise_audit.py --license-key YOUR_GUMROAD_KEY --report --remediate
88
+ ```
89
+
90
+ ### Advanced Enterprise CLI Flags
91
+ | Flag | Description | Default |
92
+ | :--- | :--- | :--- |
93
+ | `--license-key` | Gumroad enterprise license key for verification | *Required* |
94
+ | `--report` | Compiles client-ready executive PDF report | `False` |
95
+ | `--report-out` | Custom output file path for the PDF deliverable | `AWS_FinOps_Executive_Report.pdf` |
96
+ | `--remediate` | Generates `remediate_anomalies.sh` purge script | `False` |
97
+ | `--org-id` | Custom company/client name for PDF header branding | `AWS Organization Root` |
98
+ | `--regions` | Comma-separated list of AWS regions to scan | `us-east-1,us-east-2,us-west-2` |
99
+ | `--role-name` | Cross-account IAM role to assume via STS | `OrganizationAccountAccessRole` |
100
+ | `--demo` | Populates report from `sample_aws_data.csv` if live accounts show $0 waste | `False` |
101
+
102
+ ### Example: Multi-Region Scan with Custom Client Branding
103
+ ```bash
104
+ python enterprise_audit.py \
105
+ --license-key YOUR_GUMROAD_KEY \
106
+ --org-id "Acme Corp Infrastructure" \
107
+ --regions "us-east-1,us-west-2,eu-west-1" \
108
+ --report \
109
+ --report-out "Acme_FinOps_Q4_Audit.pdf" \
110
+ --remediate
111
+ ```
112
+
113
+ ---
114
+
115
+ ## 3. Executing Remediation Safely
116
+
117
+ Every audit that includes `--remediate` generates an idempotent bash script (`remediate_anomalies.sh`) with `set -euo pipefail` safety controls:
118
+
119
+ 1. **Inspect before executing:**
120
+ ```bash
121
+ cat remediate_anomalies.sh
122
+ # On Windows PowerShell:
123
+ Get-Content remediate_anomalies.sh
124
+ ```
125
+ 2. **Execute remediation purge:**
126
+ ```bash
127
+ chmod +x remediate_anomalies.sh
128
+ ./remediate_anomalies.sh
129
+ ```
130
+
131
+ *Non-destructive actions (like upgrading deprecated RDS engines) are prefixed with `#` as operational warnings and require manual review.*
132
+
133
+ ---
134
+
135
+ ## Support & Upgrades
136
+
137
+ - **Commercial Licenses & Add-ons:** [Gumroad Product Portal](https://aisser.gumroad.com/l/krgac)
138
+ - **Issues & Support:** Contact support via your Gumroad receipt portal or primary vendor email.
@@ -0,0 +1,11 @@
1
+ README.md
2
+ aws_pricing_client.py
3
+ infrastructure_auditor.py
4
+ network_auditor.py
5
+ pyproject.toml
6
+ aws_finops_auditor.egg-info/PKG-INFO
7
+ aws_finops_auditor.egg-info/SOURCES.txt
8
+ aws_finops_auditor.egg-info/dependency_links.txt
9
+ aws_finops_auditor.egg-info/entry_points.txt
10
+ aws_finops_auditor.egg-info/requires.txt
11
+ aws_finops_auditor.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ aws-finops-auditor = infrastructure_auditor:main
@@ -0,0 +1,6 @@
1
+ boto3>=1.28.0
2
+ pandas>=2.0.0
3
+
4
+ [enterprise]
5
+ fpdf>=1.7.2
6
+ requests>=2.31.0
@@ -0,0 +1,3 @@
1
+ aws_pricing_client
2
+ infrastructure_auditor
3
+ network_auditor
@@ -0,0 +1,33 @@
1
+ import pandas as pd
2
+
3
+ def fetch_live_aws_pricing():
4
+ """
5
+ Automatically pulls the weekly AWS EC2 and S3 pricing scraped by Muse
6
+ directly from the published Google Sheet into a Pandas dataframe,
7
+ without requiring local credentials from the end user.
8
+ """
9
+ # The exact Google Sheet ID
10
+ sheet_id = '1yqmuWuffbVH-S8cNr0ybMnWZX230tYl0ozLfVp6bvTo'
11
+
12
+ # Use the public CSV export URL (Requires the sheet to be "Anyone with the link can view")
13
+ csv_export_url = f"https://docs.google.com/spreadsheets/d/{sheet_id}/export?format=csv"
14
+
15
+ try:
16
+ print("Fetching latest AWS pricing data...")
17
+ pricing_df = pd.read_csv(csv_export_url)
18
+
19
+ # Clean up empty rows if Muse scraped any blank lines
20
+ pricing_df.dropna(how='all', inplace=True)
21
+ return pricing_df
22
+
23
+ except Exception as e:
24
+ print(f"[!] Failed to fetch live pricing data. Error: {e}")
25
+ print("Ensure the Google Sheet is set to 'Anyone with the link can view'.")
26
+
27
+ # Safe fallback so the audit doesn't crash if the network fails
28
+ print("Using standard fallback baseline pricing...")
29
+ return pd.DataFrame([{"Resource": "gp2", "PricePerGB": 0.08}])
30
+
31
+ if __name__ == "__main__":
32
+ live_pricing_df = fetch_live_aws_pricing()
33
+ print(live_pricing_df.head())
@@ -0,0 +1,337 @@
1
+ import hashlib
2
+ import json
3
+ import argparse
4
+ import sys
5
+ from typing import List, Dict
6
+ import pandas as pd
7
+
8
+ # License verification - Safely wrapped for Lite version graceful degradation
9
+ try:
10
+ import license_verifier
11
+ HAS_LICENSE = True
12
+ except ModuleNotFoundError:
13
+ HAS_LICENSE = False
14
+
15
+ # Enterprise Modules - Safely wrapped for Lite version graceful degradation
16
+ try:
17
+ from remediation_generator import generate_remediation_script
18
+ HAS_REMEDIATION = True
19
+ except ModuleNotFoundError:
20
+ HAS_REMEDIATION = False
21
+
22
+ try:
23
+ from compliance_exporter import generate_compliance_report
24
+ HAS_COMPLIANCE = True
25
+ except ModuleNotFoundError:
26
+ HAS_COMPLIANCE = False
27
+
28
+ try:
29
+ from executive_reporter import generate_executive_pdf
30
+ HAS_EXECUTIVE = True
31
+ except ModuleNotFoundError:
32
+ HAS_EXECUTIVE = False
33
+
34
+
35
+ def print_savings_summary(audit_findings: List[Dict]):
36
+ """
37
+ Renders a formatted terminal summary quantifying monthly and annualized waste,
38
+ displaying an immediate enterprise upgrade call-to-action.
39
+ """
40
+ total_monthly_waste = sum(item.get("monthly_cost", 0.0) for item in audit_findings)
41
+ total_annual_waste = total_monthly_waste * 12.0
42
+
43
+ width = 72
44
+ border_horiz = "═" * width
45
+ line_sep = "─" * width
46
+
47
+ print(f"\n╔{border_horiz}╗")
48
+ print(f"║{'AWS INFRASTRUCTURE POTENTIAL SAVINGS SUMMARY':^{width}}║")
49
+ print(f"╠{border_horiz}╣")
50
+ print(f"║ {'RESOURCE CATEGORY':<34} │ {'COUNT':<8} │ {'EST. MONTHLY':<23}║")
51
+ print(f"╟{line_sep}╢")
52
+
53
+ if not audit_findings:
54
+ print(f"║ {'No idle or unattached resources detected across scanned records.':<{width - 1}}║")
55
+ else:
56
+ for item in audit_findings:
57
+ name = str(item.get("category", "Resource"))[:34]
58
+ count = str(item.get("count", 0))[:8]
59
+ cost = f"${item.get('monthly_cost', 0.0):,.2f}/mo"
60
+ print(f"║ {name:<34} │ {count:<8} │ {cost:<23}║")
61
+
62
+ print(f"╠{border_horiz}╣")
63
+ print(f"║ {'TOTAL PROJECTED MONTHLY LEAK:':<45} {f'${total_monthly_waste:,.2f}':>24} ║")
64
+ print(f"║ {'ANNUALIZED CUMULATIVE WASTE:':<45} {f'${total_annual_waste:,.2f}':>24} ║")
65
+ if not (HAS_EXECUTIVE and HAS_REMEDIATION and HAS_COMPLIANCE):
66
+ print(f"╠{border_horiz}╣")
67
+ print(f"║ {'UNLOCK PDF SHOWBACK REPORTS & 1-CLICK REMEDIATION':^{width}}║")
68
+ print(f"║ {'Generate executive PDF showback reports, 1-click bash cleanup':^{width}}║")
69
+ print(f"║ {'scripts, multi-account Org scans & SOC2 audit exports:':^{width}}║")
70
+ print(f"║ {' ':^{width}}║")
71
+ print(f"║ {'-> Upgrade: https://aisser.gumroad.com/l/krgac ($99)':^{width}}║")
72
+ print(f"╚{border_horiz}╝\n")
73
+
74
+
75
+ class InfrastructureAuditor:
76
+ def __init__(self, salt: str = "infra_secure_2024"):
77
+ self.salt = salt
78
+ # Case-insensitive alias map
79
+ self.alias_map = {
80
+ 'cost': 'amount',
81
+ 'amount': 'amount',
82
+ 'usageamount': 'amount',
83
+ 'unblendedcost': 'amount',
84
+ 'totalcost': 'amount',
85
+ 'monthly_cost_usd': 'amount',
86
+ 'monthly_cost': 'amount',
87
+
88
+ 'resourceid': 'resource_id',
89
+ 'resource_id': 'resource_id',
90
+ 'instanceid': 'resource_id',
91
+ 'instance_id': 'resource_id',
92
+ 'server_id': 'resource_id',
93
+
94
+ 'publicip': 'is_public',
95
+ 'public_ip': 'is_public',
96
+ 'is_public': 'is_public',
97
+
98
+ 'cpu_util': 'cpu_utilization',
99
+ 'cpu_utilization': 'cpu_utilization',
100
+ 'cpu': 'cpu_utilization',
101
+ 'avg_cpu_usage_percent': 'cpu_utilization',
102
+ 'cpu_usage': 'cpu_utilization',
103
+
104
+ 'unattached_storage_cost_usd': 'unattached_storage_cost',
105
+ 'unattached_storage_cost': 'unattached_storage_cost',
106
+
107
+ 'is_encrypted': 'is_encrypted',
108
+ 'encrypted': 'is_encrypted'
109
+ }
110
+
111
+ def normalize_columns(self, df: pd.DataFrame) -> pd.DataFrame:
112
+ """Standardize dataframe column names with case and symbol insensitivity."""
113
+ new_cols = {}
114
+ for col in df.columns:
115
+ clean_col = str(col).strip().lower().replace(" ", "_")
116
+ if clean_col in self.alias_map:
117
+ new_cols[col] = self.alias_map[clean_col]
118
+ else:
119
+ new_cols[col] = clean_col
120
+ return df.rename(columns=new_cols)
121
+
122
+ def validate_schema(self, df: pd.DataFrame) -> None:
123
+ """Verify essential columns exist, raising helpful errors if missing."""
124
+ missing = []
125
+ if 'amount' not in df.columns:
126
+ missing.append("Cost/Amount (e.g., 'monthly_cost_usd', 'Cost', 'amount')")
127
+ if 'resource_id' not in df.columns:
128
+ missing.append("Resource ID (e.g., 'server_id', 'ResourceID', 'resource_id')")
129
+
130
+ if missing:
131
+ col_list = ", ".join([f"'{c}'" for c in df.columns])
132
+ raise ValueError(
133
+ f"Missing required columns: {', '.join(missing)}.\n"
134
+ f"Columns detected in file: [{col_list}]"
135
+ )
136
+
137
+ def anonymize_id(self, raw_id: str) -> str:
138
+ """Deterministic SHA-256 data anonymizer."""
139
+ hash_obj = hashlib.sha256(f"{str(raw_id)}{self.salt}".encode())
140
+ return hash_obj.hexdigest()[:16]
141
+
142
+ def process_data(self, df: pd.DataFrame) -> pd.DataFrame:
143
+ df = self.normalize_columns(df)
144
+ self.validate_schema(df)
145
+
146
+ # Ensure numeric type on amount
147
+ df['amount'] = pd.to_numeric(df['amount'], errors='coerce').fillna(0.0)
148
+
149
+ # Anonymize resource IDs for security
150
+ df['resource_id'] = df['resource_id'].astype(str).apply(self.anonymize_id)
151
+ return df
152
+
153
+ def calculate_waste(self, df: pd.DataFrame) -> float:
154
+ """Multi-vector financial cost-waste calculations."""
155
+ total_waste = 0.0
156
+
157
+ # 1. Idle Compute Waste (CPU < 5%)
158
+ if 'cpu_utilization' in df.columns:
159
+ cpu_series = pd.to_numeric(df['cpu_utilization'], errors='coerce')
160
+ idle_mask = (cpu_series < 5.0) | ((df['amount'] > 0) & (cpu_series.isna()))
161
+ total_waste += float(df.loc[idle_mask, 'amount'].sum())
162
+ else:
163
+ waste_mask = df['amount'] > 0
164
+ total_waste += float(df.loc[waste_mask, 'amount'].sum()) if not df.loc[waste_mask].empty else 0.0
165
+
166
+ # 2. Unattached Storage Waste
167
+ if 'unattached_storage_cost' in df.columns:
168
+ storage_series = pd.to_numeric(df['unattached_storage_cost'], errors='coerce').fillna(0.0)
169
+ total_waste += float(storage_series.sum())
170
+
171
+ return total_waste
172
+
173
+ def extract_savings_findings(self, df: pd.DataFrame) -> List[Dict]:
174
+ """Categorize individual waste vectors for terminal summary rendering."""
175
+ findings = []
176
+
177
+ # Compute analysis
178
+ if 'cpu_utilization' in df.columns:
179
+ cpu_series = pd.to_numeric(df['cpu_utilization'], errors='coerce')
180
+ idle_mask = (cpu_series < 5.0) | ((df['amount'] > 0) & (cpu_series.isna()))
181
+ idle_count = int(idle_mask.sum())
182
+ idle_cost = float(df.loc[idle_mask, 'amount'].sum())
183
+ if idle_count > 0:
184
+ findings.append({
185
+ "category": "Idle Compute (CPU < 5%)",
186
+ "count": idle_count,
187
+ "monthly_cost": round(idle_cost, 2)
188
+ })
189
+ else:
190
+ waste_mask = df['amount'] > 0
191
+ count = int(waste_mask.sum())
192
+ cost = float(df.loc[waste_mask, 'amount'].sum()) if not df.loc[waste_mask].empty else 0.0
193
+ if count > 0:
194
+ findings.append({
195
+ "category": "Unmonitored Compute Spend",
196
+ "count": count,
197
+ "monthly_cost": round(cost, 2)
198
+ })
199
+
200
+ # Storage analysis
201
+ if 'unattached_storage_cost' in df.columns:
202
+ storage_series = pd.to_numeric(df['unattached_storage_cost'], errors='coerce').fillna(0.0)
203
+ unattached_mask = storage_series > 0
204
+ storage_count = int(unattached_mask.sum())
205
+ storage_cost = float(storage_series.sum())
206
+ if storage_count > 0:
207
+ findings.append({
208
+ "category": "Unattached Storage Volumes",
209
+ "count": storage_count,
210
+ "monthly_cost": round(storage_cost, 2)
211
+ })
212
+
213
+ return findings
214
+
215
+ def detect_security_anomalies(self, df: pd.DataFrame) -> List[str]:
216
+ """Expanded security anomaly detection."""
217
+ anomalies = []
218
+
219
+ # Public IP Exposure
220
+ if 'is_public' in df.columns:
221
+ is_pub = df['is_public'].astype(str).str.strip().str.lower().isin(['true', '1', 'yes', 't'])
222
+ public_count = int(is_pub.sum())
223
+ if public_count > 0:
224
+ anomalies.append(f"CRITICAL: {public_count} resources exposed to public internet.")
225
+
226
+ # Unencrypted Resources
227
+ if 'is_encrypted' in df.columns:
228
+ is_enc = df['is_encrypted'].astype(str).str.strip().str.lower().isin(['false', '0', 'no', 'f'])
229
+ unencrypted_count = int(is_enc.sum())
230
+ if unencrypted_count > 0:
231
+ anomalies.append(f"HIGH: {unencrypted_count} resources are currently unencrypted.")
232
+
233
+ return anomalies
234
+
235
+ def generate_outputs(self, df: pd.DataFrame, results: Dict):
236
+ with open('audit_report.json', 'w', encoding='utf-8') as f:
237
+ json.dump(results, f, indent=4)
238
+
239
+ with open('executive_summary.md', 'w', encoding='utf-8') as f:
240
+ f.write("# Infrastructure Audit Summary\n\n")
241
+ f.write(f"- **Total Waste Identified:** ${results['total_waste']:,.2f}\n")
242
+ f.write(f"- **Annualized Projected Waste:** ${results['total_waste'] * 12:,.2f}\n")
243
+ f.write(f"- **Security Flags:** {len(results['anomalies'])}\n\n")
244
+ if results.get('findings'):
245
+ f.write("### Savings Breakdown\n")
246
+ for finding in results['findings']:
247
+ f.write(f"- **{finding['category']}:** {finding['count']} item(s) (${finding['monthly_cost']:,.2f}/mo)\n")
248
+ f.write("\n")
249
+ if results['anomalies']:
250
+ f.write("### Security Notices\n")
251
+ for anomaly in results['anomalies']:
252
+ f.write(f"- {anomaly}\n")
253
+ f.write("\n---\n*Generated by AWS FinOps Auditor*\n")
254
+
255
+ def run_pipeline(self, df: pd.DataFrame) -> Dict:
256
+ df = self.process_data(df)
257
+ waste = self.calculate_waste(df)
258
+ findings = self.extract_savings_findings(df)
259
+ anomalies = self.detect_security_anomalies(df)
260
+
261
+ results = {
262
+ "total_waste": round(waste, 2),
263
+ "findings": findings,
264
+ "anomalies": anomalies,
265
+ "records_analyzed": len(df)
266
+ }
267
+
268
+ self.generate_outputs(df, results)
269
+ return results
270
+
271
+
272
+ def main() -> None:
273
+ parser = argparse.ArgumentParser(description="AWS FinOps Auditor")
274
+ parser.add_argument('--file', type=str, required=True, help="Path to AWS usage CSV file")
275
+ parser.add_argument('--license-key', type=str, default=None, help="Gumroad Enterprise License Key")
276
+ parser.add_argument('--remediate', action='store_true', help="Generate executable script to delete wasted resources (Enterprise)")
277
+ parser.add_argument('--compliance', action='store_true', help="Export SOC2/ISO27001 audit evidence CSV")
278
+ args = parser.parse_args()
279
+
280
+ # Baseline license check for automated CI/CD runs
281
+ if HAS_LICENSE:
282
+ license_verifier.verify_license(license_key=args.license_key)
283
+
284
+ auditor = InfrastructureAuditor()
285
+ try:
286
+ raw_df = pd.read_csv(args.file)
287
+ print(f"Scanning {args.file} ({len(raw_df)} records)...")
288
+
289
+ # 1. Process and anonymize the data FIRST
290
+ safe_df = auditor.process_data(raw_df.copy())
291
+
292
+ # 2. Run the core pipeline with the safe data
293
+ results = auditor.run_pipeline(safe_df)
294
+
295
+ # 3. Print the formatted terminal savings summary
296
+ print_savings_summary(results.get('findings', []))
297
+
298
+ print("Audit Complete!")
299
+ print("==========================================")
300
+ print(f"Records Analyzed: {results['records_analyzed']}")
301
+ print(f"Total Waste Identified: ${results['total_waste']:,.2f}")
302
+ print(f"Security Flags: {len(results['anomalies'])}")
303
+ print("==========================================")
304
+ print("Generated 'audit_report.json' and 'executive_summary.md'.")
305
+
306
+ # 4. Pass the SAFE data to the PDF generator
307
+ if HAS_EXECUTIVE:
308
+ print("\nGenerating Executive PDF Report...")
309
+ generate_executive_pdf(safe_df)
310
+
311
+ # 5. Gated Enterprise Remediation Check
312
+ if args.remediate:
313
+ if HAS_LICENSE:
314
+ license_verifier.verify_license(license_key=args.license_key, feature_name="1-Click Automated Remediation")
315
+ if HAS_REMEDIATION:
316
+ print("\n[Enterprise Feature] Triggering automated remediation generator...")
317
+ generate_remediation_script(safe_df, "remediate_anomalies.sh")
318
+ else:
319
+ print("\n[Lite Version] 1-Click Remediation requires the Practitioner/Enterprise tier.")
320
+
321
+ # 6. Gated Enterprise Compliance Export Check
322
+ if args.compliance:
323
+ if HAS_LICENSE:
324
+ license_verifier.verify_license(license_key=args.license_key, feature_name="SOC2/ISO27001 Compliance Exporter")
325
+ if HAS_COMPLIANCE:
326
+ print("\n[Compliance Feature] Triggering SOC2/ISO27001 audit exporter...")
327
+ generate_compliance_report(safe_df)
328
+ else:
329
+ print("\n[Lite Version] SOC2/ISO27001 export requires the Practitioner/Enterprise tier.")
330
+
331
+ except Exception as e:
332
+ print(f"\n[!] Audit Failed: {e}", file=sys.stderr)
333
+ sys.exit(1)
334
+
335
+
336
+ if __name__ == '__main__':
337
+ main()
@@ -0,0 +1,90 @@
1
+ import boto3
2
+ from botocore.exceptions import NoCredentialsError, ClientError
3
+ from datetime import datetime, timedelta, timezone
4
+ from typing import Dict, Any, Optional
5
+
6
+ def audit_idle_network_costs(session: Optional[boto3.Session] = None, region_name: str = "us-east-1") -> Dict[str, Any]:
7
+ """
8
+ Audits unassociated Elastic IPs and idle NAT Gateways using an optional boto3.Session.
9
+ """
10
+ results = {
11
+ "region": region_name,
12
+ "unassociated_eips": [],
13
+ "idle_nat_gateways": [],
14
+ "monthly_waste_estimate": 0.0,
15
+ "errors": []
16
+ }
17
+
18
+ active_session = session or boto3.Session()
19
+
20
+ try:
21
+ ec2 = active_session.client("ec2", region_name=region_name)
22
+ cw = active_session.client("cloudwatch", region_name=region_name)
23
+ except Exception as e:
24
+ results["errors"].append(f"Client initialization failed: {e}")
25
+ return results
26
+
27
+ now = datetime.now(timezone.utc)
28
+ seven_days_ago = now - timedelta(days=7)
29
+
30
+ # 1. Audit Unattached Elastic IPs ($0.005/hr = ~$3.60/month each)
31
+ try:
32
+ addresses = ec2.describe_addresses().get("Addresses", [])
33
+ for addr in addresses:
34
+ if "AssociationId" not in addr and "InstanceId" not in addr:
35
+ eip_data = {
36
+ "AllocationId": addr.get("AllocationId", "N/A"),
37
+ "PublicIp": addr.get("PublicIp", "N/A"),
38
+ "NetworkBorderGroup": addr.get("NetworkBorderGroup", region_name),
39
+ "MonthlyCost": 3.60,
40
+ }
41
+ results["unassociated_eips"].append(eip_data)
42
+ results["monthly_waste_estimate"] += 3.60
43
+ except NoCredentialsError:
44
+ results["errors"].append("Authentication failed: No AWS credentials found.")
45
+ return results
46
+ except ClientError as e:
47
+ results["errors"].append(f"EC2 describe_addresses error: {e}")
48
+
49
+ # 2. Audit Idle NAT Gateways ($0.045/hr base = ~$32.40/month each)
50
+ try:
51
+ nat_gateways = ec2.describe_nat_gateways(
52
+ Filters=[{"Name": "state", "Values": ["available"]}]
53
+ ).get("NatGateways", [])
54
+
55
+ for nat in nat_gateways:
56
+ nat_id = nat["NatGatewayId"]
57
+ metric_resp = cw.get_metric_statistics(
58
+ Namespace="AWS/NATGateway",
59
+ MetricName="BytesOutFromDestination",
60
+ Dimensions=[{"Name": "NatGatewayId", "Value": nat_id}],
61
+ StartTime=seven_days_ago,
62
+ EndTime=now,
63
+ Period=604800,
64
+ Statistics=["Sum"],
65
+ )
66
+ datapoints = metric_resp.get("Datapoints", [])
67
+ total_bytes = datapoints[0]["Sum"] if datapoints else 0
68
+
69
+ # Flag gateways transferring less than 1 MB over 7 consecutive days
70
+ if total_bytes < 1_000_000:
71
+ nat_data = {
72
+ "NatGatewayId": nat_id,
73
+ "VpcId": nat.get("VpcId", "N/A"),
74
+ "SubnetId": nat.get("SubnetId", "N/A"),
75
+ "BytesTransferred7d": total_bytes,
76
+ "MonthlyCost": 32.40,
77
+ }
78
+ results["idle_nat_gateways"].append(nat_data)
79
+ results["monthly_waste_estimate"] += 32.40
80
+ except NoCredentialsError:
81
+ results["errors"].append("Authentication failed: No AWS credentials found.")
82
+ except ClientError as e:
83
+ results["errors"].append(f"CloudWatch/NATGateway error: {e}")
84
+
85
+ return results
86
+
87
+ if __name__ == "__main__":
88
+ import json
89
+ report = audit_idle_network_costs()
90
+ print(json.dumps(report, indent=2))
@@ -0,0 +1,52 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "aws-finops-auditor"
7
+ version = "1.0.0"
8
+ description = "Read-only AWS FinOps CLI auditor for identifying idle compute, orphaned storage, and unattached network waste."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ license-files = []
13
+ authors = [
14
+ { name = "Aisser Rodriguez" }
15
+ ]
16
+ keywords = ["aws", "finops", "cloud-cost", "cost-optimization", "devops", "cli"]
17
+ classifiers = [
18
+ "Development Status :: 5 - Production/Stable",
19
+ "Intended Audience :: Developers",
20
+ "Intended Audience :: System Administrators",
21
+ "Topic :: System :: Systems Administration",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3.9",
24
+ "Programming Language :: Python :: 3.10",
25
+ "Programming Language :: Python :: 3.11",
26
+ "Programming Language :: Python :: 3.12",
27
+ ]
28
+ dependencies = [
29
+ "boto3>=1.28.0",
30
+ "pandas>=2.0.0",
31
+ ]
32
+
33
+ [project.optional-dependencies]
34
+ enterprise = [
35
+ "fpdf>=1.7.2",
36
+ "requests>=2.31.0",
37
+ ]
38
+
39
+ [project.urls]
40
+ Homepage = "https://github.com/Ace-FinOps-Enterprise/aws-finops-auditor"
41
+ Repository = "https://github.com/Ace-FinOps-Enterprise/aws-finops-auditor"
42
+ "Practitioner & Enterprise Tiers" = "https://aisser.gumroad.com/l/krgac"
43
+
44
+ [project.scripts]
45
+ aws-finops-auditor = "infrastructure_auditor:main"
46
+
47
+ [tool.setuptools]
48
+ py-modules = [
49
+ "infrastructure_auditor",
50
+ "aws_pricing_client",
51
+ "network_auditor",
52
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+