runbooks 1.1.3__py3-none-any.whl → 1.1.5__py3-none-any.whl

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.
Files changed (247) hide show
  1. runbooks/__init__.py +31 -2
  2. runbooks/__init___optimized.py +18 -4
  3. runbooks/_platform/__init__.py +1 -5
  4. runbooks/_platform/core/runbooks_wrapper.py +141 -138
  5. runbooks/aws2/accuracy_validator.py +812 -0
  6. runbooks/base.py +7 -0
  7. runbooks/cfat/WEIGHT_CONFIG_README.md +1 -1
  8. runbooks/cfat/assessment/compliance.py +8 -8
  9. runbooks/cfat/assessment/runner.py +1 -0
  10. runbooks/cfat/cloud_foundations_assessment.py +227 -239
  11. runbooks/cfat/models.py +6 -2
  12. runbooks/cfat/tests/__init__.py +6 -1
  13. runbooks/cli/__init__.py +13 -0
  14. runbooks/cli/commands/cfat.py +274 -0
  15. runbooks/cli/commands/finops.py +1164 -0
  16. runbooks/cli/commands/inventory.py +379 -0
  17. runbooks/cli/commands/operate.py +239 -0
  18. runbooks/cli/commands/security.py +248 -0
  19. runbooks/cli/commands/validation.py +825 -0
  20. runbooks/cli/commands/vpc.py +310 -0
  21. runbooks/cli/registry.py +107 -0
  22. runbooks/cloudops/__init__.py +23 -30
  23. runbooks/cloudops/base.py +96 -107
  24. runbooks/cloudops/cost_optimizer.py +549 -547
  25. runbooks/cloudops/infrastructure_optimizer.py +5 -4
  26. runbooks/cloudops/interfaces.py +226 -227
  27. runbooks/cloudops/lifecycle_manager.py +5 -4
  28. runbooks/cloudops/mcp_cost_validation.py +252 -235
  29. runbooks/cloudops/models.py +78 -53
  30. runbooks/cloudops/monitoring_automation.py +5 -4
  31. runbooks/cloudops/notebook_framework.py +179 -215
  32. runbooks/cloudops/security_enforcer.py +125 -159
  33. runbooks/common/accuracy_validator.py +11 -0
  34. runbooks/common/aws_pricing.py +349 -326
  35. runbooks/common/aws_pricing_api.py +211 -212
  36. runbooks/common/aws_profile_manager.py +341 -0
  37. runbooks/common/aws_utils.py +75 -80
  38. runbooks/common/business_logic.py +127 -105
  39. runbooks/common/cli_decorators.py +36 -60
  40. runbooks/common/comprehensive_cost_explorer_integration.py +456 -464
  41. runbooks/common/cross_account_manager.py +198 -205
  42. runbooks/common/date_utils.py +27 -39
  43. runbooks/common/decorators.py +235 -0
  44. runbooks/common/dry_run_examples.py +173 -208
  45. runbooks/common/dry_run_framework.py +157 -155
  46. runbooks/common/enhanced_exception_handler.py +15 -4
  47. runbooks/common/enhanced_logging_example.py +50 -64
  48. runbooks/common/enhanced_logging_integration_example.py +65 -37
  49. runbooks/common/env_utils.py +16 -16
  50. runbooks/common/error_handling.py +40 -38
  51. runbooks/common/lazy_loader.py +41 -23
  52. runbooks/common/logging_integration_helper.py +79 -86
  53. runbooks/common/mcp_cost_explorer_integration.py +478 -495
  54. runbooks/common/mcp_integration.py +63 -74
  55. runbooks/common/memory_optimization.py +140 -118
  56. runbooks/common/module_cli_base.py +37 -58
  57. runbooks/common/organizations_client.py +176 -194
  58. runbooks/common/patterns.py +204 -0
  59. runbooks/common/performance_monitoring.py +67 -71
  60. runbooks/common/performance_optimization_engine.py +283 -274
  61. runbooks/common/profile_utils.py +248 -39
  62. runbooks/common/rich_utils.py +643 -92
  63. runbooks/common/sre_performance_suite.py +177 -186
  64. runbooks/enterprise/__init__.py +1 -1
  65. runbooks/enterprise/logging.py +144 -106
  66. runbooks/enterprise/security.py +187 -204
  67. runbooks/enterprise/validation.py +43 -56
  68. runbooks/finops/__init__.py +29 -33
  69. runbooks/finops/account_resolver.py +1 -1
  70. runbooks/finops/advanced_optimization_engine.py +980 -0
  71. runbooks/finops/automation_core.py +268 -231
  72. runbooks/finops/business_case_config.py +184 -179
  73. runbooks/finops/cli.py +660 -139
  74. runbooks/finops/commvault_ec2_analysis.py +157 -164
  75. runbooks/finops/compute_cost_optimizer.py +336 -320
  76. runbooks/finops/config.py +20 -20
  77. runbooks/finops/cost_optimizer.py +488 -622
  78. runbooks/finops/cost_processor.py +332 -214
  79. runbooks/finops/dashboard_runner.py +1006 -172
  80. runbooks/finops/ebs_cost_optimizer.py +991 -657
  81. runbooks/finops/elastic_ip_optimizer.py +317 -257
  82. runbooks/finops/enhanced_mcp_integration.py +340 -0
  83. runbooks/finops/enhanced_progress.py +40 -37
  84. runbooks/finops/enhanced_trend_visualization.py +3 -2
  85. runbooks/finops/enterprise_wrappers.py +230 -292
  86. runbooks/finops/executive_export.py +203 -160
  87. runbooks/finops/helpers.py +130 -288
  88. runbooks/finops/iam_guidance.py +1 -1
  89. runbooks/finops/infrastructure/__init__.py +80 -0
  90. runbooks/finops/infrastructure/commands.py +506 -0
  91. runbooks/finops/infrastructure/load_balancer_optimizer.py +866 -0
  92. runbooks/finops/infrastructure/vpc_endpoint_optimizer.py +832 -0
  93. runbooks/finops/markdown_exporter.py +338 -175
  94. runbooks/finops/mcp_validator.py +1952 -0
  95. runbooks/finops/nat_gateway_optimizer.py +1513 -482
  96. runbooks/finops/network_cost_optimizer.py +657 -587
  97. runbooks/finops/notebook_utils.py +226 -188
  98. runbooks/finops/optimization_engine.py +1136 -0
  99. runbooks/finops/optimizer.py +25 -29
  100. runbooks/finops/rds_snapshot_optimizer.py +367 -411
  101. runbooks/finops/reservation_optimizer.py +427 -363
  102. runbooks/finops/scenario_cli_integration.py +77 -78
  103. runbooks/finops/scenarios.py +1278 -439
  104. runbooks/finops/schemas.py +218 -182
  105. runbooks/finops/snapshot_manager.py +2289 -0
  106. runbooks/finops/tests/test_finops_dashboard.py +3 -3
  107. runbooks/finops/tests/test_reference_images_validation.py +2 -2
  108. runbooks/finops/tests/test_single_account_features.py +17 -17
  109. runbooks/finops/tests/validate_test_suite.py +1 -1
  110. runbooks/finops/types.py +3 -3
  111. runbooks/finops/validation_framework.py +263 -269
  112. runbooks/finops/vpc_cleanup_exporter.py +191 -146
  113. runbooks/finops/vpc_cleanup_optimizer.py +593 -575
  114. runbooks/finops/workspaces_analyzer.py +171 -182
  115. runbooks/hitl/enhanced_workflow_engine.py +1 -1
  116. runbooks/integration/__init__.py +89 -0
  117. runbooks/integration/mcp_integration.py +1920 -0
  118. runbooks/inventory/CLAUDE.md +816 -0
  119. runbooks/inventory/README.md +3 -3
  120. runbooks/inventory/Tests/common_test_data.py +30 -30
  121. runbooks/inventory/__init__.py +2 -2
  122. runbooks/inventory/cloud_foundations_integration.py +144 -149
  123. runbooks/inventory/collectors/aws_comprehensive.py +28 -11
  124. runbooks/inventory/collectors/aws_networking.py +111 -101
  125. runbooks/inventory/collectors/base.py +4 -0
  126. runbooks/inventory/core/collector.py +495 -313
  127. runbooks/inventory/discovery.md +2 -2
  128. runbooks/inventory/drift_detection_cli.py +69 -96
  129. runbooks/inventory/find_ec2_security_groups.py +1 -1
  130. runbooks/inventory/inventory_mcp_cli.py +48 -46
  131. runbooks/inventory/list_rds_snapshots_aggregator.py +192 -208
  132. runbooks/inventory/mcp_inventory_validator.py +549 -465
  133. runbooks/inventory/mcp_vpc_validator.py +359 -442
  134. runbooks/inventory/organizations_discovery.py +56 -52
  135. runbooks/inventory/rich_inventory_display.py +33 -32
  136. runbooks/inventory/unified_validation_engine.py +278 -251
  137. runbooks/inventory/vpc_analyzer.py +733 -696
  138. runbooks/inventory/vpc_architecture_validator.py +293 -348
  139. runbooks/inventory/vpc_dependency_analyzer.py +382 -378
  140. runbooks/inventory/vpc_flow_analyzer.py +3 -3
  141. runbooks/main.py +152 -9147
  142. runbooks/main_final.py +91 -60
  143. runbooks/main_minimal.py +22 -10
  144. runbooks/main_optimized.py +131 -100
  145. runbooks/main_ultra_minimal.py +7 -2
  146. runbooks/mcp/__init__.py +36 -0
  147. runbooks/mcp/integration.py +679 -0
  148. runbooks/metrics/dora_metrics_engine.py +2 -2
  149. runbooks/monitoring/performance_monitor.py +9 -4
  150. runbooks/operate/dynamodb_operations.py +3 -1
  151. runbooks/operate/ec2_operations.py +145 -137
  152. runbooks/operate/iam_operations.py +146 -152
  153. runbooks/operate/mcp_integration.py +1 -1
  154. runbooks/operate/networking_cost_heatmap.py +33 -10
  155. runbooks/operate/privatelink_operations.py +1 -1
  156. runbooks/operate/rds_operations.py +223 -254
  157. runbooks/operate/s3_operations.py +107 -118
  158. runbooks/operate/vpc_endpoints.py +1 -1
  159. runbooks/operate/vpc_operations.py +648 -618
  160. runbooks/remediation/base.py +1 -1
  161. runbooks/remediation/commons.py +10 -7
  162. runbooks/remediation/commvault_ec2_analysis.py +71 -67
  163. runbooks/remediation/ec2_unattached_ebs_volumes.py +1 -0
  164. runbooks/remediation/multi_account.py +24 -21
  165. runbooks/remediation/rds_snapshot_list.py +91 -65
  166. runbooks/remediation/remediation_cli.py +92 -146
  167. runbooks/remediation/universal_account_discovery.py +83 -79
  168. runbooks/remediation/workspaces_list.py +49 -44
  169. runbooks/security/__init__.py +19 -0
  170. runbooks/security/assessment_runner.py +1150 -0
  171. runbooks/security/baseline_checker.py +812 -0
  172. runbooks/security/cloudops_automation_security_validator.py +509 -535
  173. runbooks/security/compliance_automation_engine.py +17 -17
  174. runbooks/security/config/__init__.py +2 -2
  175. runbooks/security/config/compliance_config.py +50 -50
  176. runbooks/security/config_template_generator.py +63 -76
  177. runbooks/security/enterprise_security_framework.py +1 -1
  178. runbooks/security/executive_security_dashboard.py +519 -508
  179. runbooks/security/integration_test_enterprise_security.py +5 -3
  180. runbooks/security/multi_account_security_controls.py +959 -1210
  181. runbooks/security/real_time_security_monitor.py +422 -444
  182. runbooks/security/run_script.py +1 -1
  183. runbooks/security/security_baseline_tester.py +1 -1
  184. runbooks/security/security_cli.py +143 -112
  185. runbooks/security/test_2way_validation.py +439 -0
  186. runbooks/security/two_way_validation_framework.py +852 -0
  187. runbooks/sre/mcp_reliability_engine.py +6 -6
  188. runbooks/sre/production_monitoring_framework.py +167 -177
  189. runbooks/tdd/__init__.py +15 -0
  190. runbooks/tdd/cli.py +1071 -0
  191. runbooks/utils/__init__.py +14 -17
  192. runbooks/utils/logger.py +7 -2
  193. runbooks/utils/version_validator.py +51 -48
  194. runbooks/validation/__init__.py +6 -6
  195. runbooks/validation/cli.py +9 -3
  196. runbooks/validation/comprehensive_2way_validator.py +754 -708
  197. runbooks/validation/mcp_validator.py +906 -228
  198. runbooks/validation/terraform_citations_validator.py +104 -115
  199. runbooks/validation/terraform_drift_detector.py +447 -451
  200. runbooks/vpc/README.md +617 -0
  201. runbooks/vpc/__init__.py +8 -1
  202. runbooks/vpc/analyzer.py +577 -0
  203. runbooks/vpc/cleanup_wrapper.py +476 -413
  204. runbooks/vpc/cli_cloudtrail_commands.py +339 -0
  205. runbooks/vpc/cli_mcp_validation_commands.py +480 -0
  206. runbooks/vpc/cloudtrail_audit_integration.py +717 -0
  207. runbooks/vpc/config.py +92 -97
  208. runbooks/vpc/cost_engine.py +411 -148
  209. runbooks/vpc/cost_explorer_integration.py +553 -0
  210. runbooks/vpc/cross_account_session.py +101 -106
  211. runbooks/vpc/enhanced_mcp_validation.py +917 -0
  212. runbooks/vpc/eni_gate_validator.py +961 -0
  213. runbooks/vpc/heatmap_engine.py +190 -162
  214. runbooks/vpc/mcp_no_eni_validator.py +681 -640
  215. runbooks/vpc/nat_gateway_optimizer.py +358 -0
  216. runbooks/vpc/networking_wrapper.py +15 -8
  217. runbooks/vpc/pdca_remediation_planner.py +528 -0
  218. runbooks/vpc/performance_optimized_analyzer.py +219 -231
  219. runbooks/vpc/runbooks_adapter.py +1167 -241
  220. runbooks/vpc/tdd_red_phase_stubs.py +601 -0
  221. runbooks/vpc/test_data_loader.py +358 -0
  222. runbooks/vpc/tests/conftest.py +314 -4
  223. runbooks/vpc/tests/test_cleanup_framework.py +1022 -0
  224. runbooks/vpc/tests/test_cost_engine.py +0 -2
  225. runbooks/vpc/topology_generator.py +326 -0
  226. runbooks/vpc/unified_scenarios.py +1302 -1129
  227. runbooks/vpc/vpc_cleanup_integration.py +1943 -1115
  228. runbooks-1.1.5.dist-info/METADATA +328 -0
  229. {runbooks-1.1.3.dist-info → runbooks-1.1.5.dist-info}/RECORD +233 -200
  230. runbooks/finops/README.md +0 -414
  231. runbooks/finops/accuracy_cross_validator.py +0 -647
  232. runbooks/finops/business_cases.py +0 -950
  233. runbooks/finops/dashboard_router.py +0 -922
  234. runbooks/finops/ebs_optimizer.py +0 -956
  235. runbooks/finops/embedded_mcp_validator.py +0 -1629
  236. runbooks/finops/enhanced_dashboard_runner.py +0 -527
  237. runbooks/finops/finops_dashboard.py +0 -584
  238. runbooks/finops/finops_scenarios.py +0 -1218
  239. runbooks/finops/legacy_migration.py +0 -730
  240. runbooks/finops/multi_dashboard.py +0 -1519
  241. runbooks/finops/single_dashboard.py +0 -1113
  242. runbooks/finops/unlimited_scenarios.py +0 -393
  243. runbooks-1.1.3.dist-info/METADATA +0 -799
  244. {runbooks-1.1.3.dist-info → runbooks-1.1.5.dist-info}/WHEEL +0 -0
  245. {runbooks-1.1.3.dist-info → runbooks-1.1.5.dist-info}/entry_points.txt +0 -0
  246. {runbooks-1.1.3.dist-info → runbooks-1.1.5.dist-info}/licenses/LICENSE +0 -0
  247. {runbooks-1.1.3.dist-info → runbooks-1.1.5.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,980 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Advanced Cost Optimization Engine for Enhanced FinOps Dashboard
4
+
5
+ This module provides sophisticated cost optimization analysis with:
6
+ - Service-specific optimization recommendations with actual cost impact
7
+ - ROI calculations and payback period analysis
8
+ - Priority scoring based on business impact
9
+ - Implementation guidance with specific action steps
10
+ - Risk assessment and implementation complexity scoring
11
+ """
12
+
13
+ from dataclasses import dataclass
14
+ from datetime import datetime, timedelta
15
+ from decimal import Decimal
16
+ from typing import Dict, List, Optional, Tuple
17
+
18
+ import boto3
19
+ from rich.console import Console
20
+ from rich.panel import Panel
21
+ from rich.table import Table
22
+
23
+ console = Console()
24
+
25
+
26
+ @dataclass
27
+ class OptimizationRecommendation:
28
+ """Enhanced optimization recommendation with business context"""
29
+
30
+ service_name: str
31
+ resource_type: str
32
+ current_monthly_cost: float
33
+ potential_monthly_savings: float
34
+ potential_annual_savings: float
35
+ confidence_level: str # HIGH, MEDIUM, LOW
36
+ priority_score: int # 1-10 (10 = highest priority)
37
+ implementation_complexity: str # SIMPLE, MODERATE, COMPLEX
38
+ risk_level: str # LOW, MEDIUM, HIGH
39
+ payback_period_months: int
40
+ roi_percentage: float
41
+ description: str
42
+ action_steps: List[str]
43
+ business_impact: str
44
+ resource_count: int = 0
45
+ tags: Optional[Dict] = None
46
+
47
+
48
+ @dataclass
49
+ class ServiceOptimizationResults:
50
+ """Results for a specific service optimization analysis"""
51
+
52
+ service_name: str
53
+ total_monthly_cost: float
54
+ total_potential_savings: float
55
+ recommendations: List[OptimizationRecommendation]
56
+ optimization_percentage: float
57
+ priority_actions: List[str]
58
+
59
+
60
+ class AdvancedOptimizationEngine:
61
+ """
62
+ Advanced cost optimization engine providing detailed, actionable recommendations
63
+ with business impact analysis and implementation guidance.
64
+ """
65
+
66
+ def __init__(self, profile: str):
67
+ self.profile = profile
68
+ self.console = Console()
69
+
70
+ # Service optimization strategies
71
+ self.service_optimizers = {
72
+ "ec2": self._optimize_ec2_recommendations,
73
+ "rds": self._optimize_rds_recommendations,
74
+ "s3": self._optimize_s3_recommendations,
75
+ "lambda": self._optimize_lambda_recommendations,
76
+ "cloudwatch": self._optimize_cloudwatch_recommendations,
77
+ "dynamodb": self._optimize_dynamodb_recommendations,
78
+ "ebs": self._optimize_ebs_recommendations,
79
+ "nat_gateway": self._optimize_nat_gateway_recommendations,
80
+ "data_transfer": self._optimize_data_transfer_recommendations,
81
+ "savings_plans": self._optimize_savings_plans_recommendations,
82
+ }
83
+
84
+ def analyze_service_optimization(
85
+ self, service_name: str, monthly_cost: float, previous_cost: float = 0.0
86
+ ) -> ServiceOptimizationResults:
87
+ """
88
+ Analyze optimization opportunities for a specific service
89
+ """
90
+ service_key = self._normalize_service_name(service_name)
91
+
92
+ if service_key in self.service_optimizers:
93
+ return self.service_optimizers[service_key](service_name, monthly_cost, previous_cost)
94
+ else:
95
+ return self._generic_service_optimization(service_name, monthly_cost, previous_cost)
96
+
97
+ def _normalize_service_name(self, service_name: str) -> str:
98
+ """Normalize service names to match our optimization strategies"""
99
+ service_lower = service_name.lower()
100
+
101
+ if "ec2" in service_lower or "elastic compute" in service_lower:
102
+ return "ec2"
103
+ elif "rds" in service_lower or "database" in service_lower:
104
+ return "rds"
105
+ elif "s3" in service_lower or "simple storage" in service_lower:
106
+ return "s3"
107
+ elif "lambda" in service_lower:
108
+ return "lambda"
109
+ elif "cloudwatch" in service_lower:
110
+ return "cloudwatch"
111
+ elif "dynamodb" in service_lower:
112
+ return "dynamodb"
113
+ elif "nat" in service_lower and "gateway" in service_lower:
114
+ return "nat_gateway"
115
+ elif "data transfer" in service_lower or "bandwidth" in service_lower:
116
+ return "data_transfer"
117
+ elif "savings plan" in service_lower:
118
+ return "savings_plans"
119
+ elif "ebs" in service_lower or "elastic block" in service_lower:
120
+ return "ebs"
121
+ else:
122
+ return "generic"
123
+
124
+ def _optimize_ec2_recommendations(
125
+ self, service_name: str, monthly_cost: float, previous_cost: float
126
+ ) -> ServiceOptimizationResults:
127
+ """EC2-specific optimization recommendations"""
128
+ recommendations = []
129
+
130
+ # High-cost EC2 optimizations
131
+ if monthly_cost > 5000:
132
+ # Reserved Instances recommendation
133
+ reserved_savings = monthly_cost * 0.30 # 30% typical RI savings
134
+ recommendations.append(
135
+ OptimizationRecommendation(
136
+ service_name=service_name,
137
+ resource_type="Reserved Instances",
138
+ current_monthly_cost=monthly_cost,
139
+ potential_monthly_savings=reserved_savings,
140
+ potential_annual_savings=reserved_savings * 12,
141
+ confidence_level="HIGH",
142
+ priority_score=9,
143
+ implementation_complexity="SIMPLE",
144
+ risk_level="LOW",
145
+ payback_period_months=0, # Immediate savings
146
+ roi_percentage=30.0,
147
+ description=f"Convert {monthly_cost / 200:.0f} On-Demand instances to Reserved Instances",
148
+ action_steps=[
149
+ "1. Analyze instance usage patterns over past 3 months",
150
+ "2. Identify steady-state instances running >75% of time",
151
+ "3. Purchase 1-year Standard RIs for consistent workloads",
152
+ "4. Consider 3-year RIs for long-term stable workloads",
153
+ "5. Monitor RI utilization and adjust as needed",
154
+ ],
155
+ business_impact=f"Immediate cost reduction of ${reserved_savings:,.0f}/month with guaranteed savings",
156
+ resource_count=int(monthly_cost / 200), # Assume $200/month per instance
157
+ )
158
+ )
159
+
160
+ # Right-sizing recommendation
161
+ rightsizing_savings = monthly_cost * 0.15 # 15% typical rightsizing
162
+ recommendations.append(
163
+ OptimizationRecommendation(
164
+ service_name=service_name,
165
+ resource_type="Instance Right-sizing",
166
+ current_monthly_cost=monthly_cost,
167
+ potential_monthly_savings=rightsizing_savings,
168
+ potential_annual_savings=rightsizing_savings * 12,
169
+ confidence_level="MEDIUM",
170
+ priority_score=7,
171
+ implementation_complexity="MODERATE",
172
+ risk_level="MEDIUM",
173
+ payback_period_months=1,
174
+ roi_percentage=15.0,
175
+ description="Right-size over-provisioned EC2 instances based on utilization",
176
+ action_steps=[
177
+ "1. Enable CloudWatch detailed monitoring for all instances",
178
+ "2. Collect CPU, memory, and network utilization for 14 days",
179
+ "3. Identify instances with <40% average CPU utilization",
180
+ "4. Test smaller instance types in staging environment",
181
+ "5. Implement changes during maintenance windows",
182
+ ],
183
+ business_impact=f"Reduce monthly spend by ${rightsizing_savings:,.0f} through optimal instance sizing",
184
+ resource_count=int(monthly_cost / 200 * 0.3), # 30% of instances could be rightsized
185
+ )
186
+ )
187
+
188
+ # Spot instance recommendation for appropriate workloads
189
+ if monthly_cost > 1000:
190
+ spot_savings = monthly_cost * 0.60 # 60% typical spot savings
191
+ recommendations.append(
192
+ OptimizationRecommendation(
193
+ service_name=service_name,
194
+ resource_type="Spot Instances",
195
+ current_monthly_cost=monthly_cost,
196
+ potential_monthly_savings=spot_savings,
197
+ potential_annual_savings=spot_savings * 12,
198
+ confidence_level="MEDIUM",
199
+ priority_score=6,
200
+ implementation_complexity="COMPLEX",
201
+ risk_level="HIGH",
202
+ payback_period_months=0,
203
+ roi_percentage=60.0,
204
+ description="Migrate fault-tolerant workloads to EC2 Spot Instances",
205
+ action_steps=[
206
+ "1. Identify stateless, fault-tolerant applications",
207
+ "2. Implement auto-scaling with mixed instance types",
208
+ "3. Set up spot fleet requests with multiple AZs",
209
+ "4. Create spot instance interruption handling",
210
+ "5. Monitor spot pricing trends and optimize bidding",
211
+ ],
212
+ business_impact=f"Up to ${spot_savings:,.0f}/month savings for suitable workloads",
213
+ resource_count=int(monthly_cost / 200 * 0.2), # 20% suitable for spot
214
+ )
215
+ )
216
+
217
+ total_potential = sum(rec.potential_monthly_savings for rec in recommendations)
218
+ optimization_percentage = (total_potential / monthly_cost * 100) if monthly_cost > 0 else 0
219
+
220
+ priority_actions = [
221
+ "🎯 Start with Reserved Instance analysis - highest ROI, lowest risk",
222
+ "📊 Enable detailed monitoring to identify rightsizing opportunities",
223
+ "⚡ Evaluate spot instances for development and batch workloads",
224
+ ]
225
+
226
+ return ServiceOptimizationResults(
227
+ service_name=service_name,
228
+ total_monthly_cost=monthly_cost,
229
+ total_potential_savings=total_potential,
230
+ recommendations=recommendations,
231
+ optimization_percentage=optimization_percentage,
232
+ priority_actions=priority_actions,
233
+ )
234
+
235
+ def _optimize_s3_recommendations(
236
+ self, service_name: str, monthly_cost: float, previous_cost: float
237
+ ) -> ServiceOptimizationResults:
238
+ """S3-specific optimization recommendations"""
239
+ recommendations = []
240
+
241
+ if monthly_cost > 500:
242
+ # Intelligent Tiering
243
+ tiering_savings = monthly_cost * 0.25 # 25% typical savings
244
+ recommendations.append(
245
+ OptimizationRecommendation(
246
+ service_name=service_name,
247
+ resource_type="Intelligent Tiering",
248
+ current_monthly_cost=monthly_cost,
249
+ potential_monthly_savings=tiering_savings,
250
+ potential_annual_savings=tiering_savings * 12,
251
+ confidence_level="HIGH",
252
+ priority_score=8,
253
+ implementation_complexity="SIMPLE",
254
+ risk_level="LOW",
255
+ payback_period_months=1,
256
+ roi_percentage=25.0,
257
+ description="Enable S3 Intelligent Tiering for automatic cost optimization",
258
+ action_steps=[
259
+ "1. Analyze storage access patterns using S3 Storage Lens",
260
+ "2. Enable Intelligent Tiering for buckets >128KB objects",
261
+ "3. Set up lifecycle policies for infrequent access data",
262
+ "4. Monitor tiering effectiveness monthly",
263
+ "5. Consider Deep Archive for compliance data",
264
+ ],
265
+ business_impact=f"Automatic storage optimization saving ${tiering_savings:,.0f}/month",
266
+ resource_count=0,
267
+ )
268
+ )
269
+
270
+ # Lifecycle policies
271
+ lifecycle_savings = monthly_cost * 0.30 # 30% savings potential
272
+ recommendations.append(
273
+ OptimizationRecommendation(
274
+ service_name=service_name,
275
+ resource_type="Lifecycle Management",
276
+ current_monthly_cost=monthly_cost,
277
+ potential_monthly_savings=lifecycle_savings,
278
+ potential_annual_savings=lifecycle_savings * 12,
279
+ confidence_level="MEDIUM",
280
+ priority_score=7,
281
+ implementation_complexity="MODERATE",
282
+ risk_level="LOW",
283
+ payback_period_months=2,
284
+ roi_percentage=30.0,
285
+ description="Implement comprehensive lifecycle policies for data archival",
286
+ action_steps=[
287
+ "1. Audit data access patterns over 6 months",
288
+ "2. Define retention policies by data type",
289
+ "3. Create lifecycle rules: IA (30d), Glacier (90d), Deep Archive (365d)",
290
+ "4. Test policies on non-critical buckets first",
291
+ "5. Monitor cost impact and adjust rules",
292
+ ],
293
+ business_impact=f"Long-term storage optimization saving ${lifecycle_savings:,.0f}/month",
294
+ resource_count=0,
295
+ )
296
+ )
297
+
298
+ total_potential = sum(rec.potential_monthly_savings for rec in recommendations)
299
+ optimization_percentage = (total_potential / monthly_cost * 100) if monthly_cost > 0 else 0
300
+
301
+ priority_actions = [
302
+ "📦 Enable S3 Intelligent Tiering for immediate automated savings",
303
+ "🔄 Implement lifecycle policies for long-term cost control",
304
+ "📊 Use S3 Storage Lens for usage pattern analysis",
305
+ ]
306
+
307
+ return ServiceOptimizationResults(
308
+ service_name=service_name,
309
+ total_monthly_cost=monthly_cost,
310
+ total_potential_savings=total_potential,
311
+ recommendations=recommendations,
312
+ optimization_percentage=optimization_percentage,
313
+ priority_actions=priority_actions,
314
+ )
315
+
316
+ def _optimize_rds_recommendations(
317
+ self, service_name: str, monthly_cost: float, previous_cost: float
318
+ ) -> ServiceOptimizationResults:
319
+ """RDS-specific optimization recommendations"""
320
+ recommendations = []
321
+
322
+ if monthly_cost > 2000:
323
+ # Reserved Instances for RDS
324
+ rds_ri_savings = monthly_cost * 0.35 # 35% typical RDS RI savings
325
+ recommendations.append(
326
+ OptimizationRecommendation(
327
+ service_name=service_name,
328
+ resource_type="RDS Reserved Instances",
329
+ current_monthly_cost=monthly_cost,
330
+ potential_monthly_savings=rds_ri_savings,
331
+ potential_annual_savings=rds_ri_savings * 12,
332
+ confidence_level="HIGH",
333
+ priority_score=9,
334
+ implementation_complexity="SIMPLE",
335
+ risk_level="LOW",
336
+ payback_period_months=0,
337
+ roi_percentage=35.0,
338
+ description="Purchase RDS Reserved Instances for production databases",
339
+ action_steps=[
340
+ "1. Identify production RDS instances with consistent usage",
341
+ "2. Analyze historical utilization patterns",
342
+ "3. Purchase 1-year RDS RIs for stable workloads",
343
+ "4. Consider 3-year RIs for long-term databases",
344
+ "5. Monitor RI utilization and coverage",
345
+ ],
346
+ business_impact=f"Immediate database cost reduction of ${rds_ri_savings:,.0f}/month",
347
+ resource_count=int(monthly_cost / 400), # Assume $400/month per DB instance
348
+ )
349
+ )
350
+
351
+ # Right-sizing databases
352
+ db_rightsizing = monthly_cost * 0.20 # 20% rightsizing potential
353
+ recommendations.append(
354
+ OptimizationRecommendation(
355
+ service_name=service_name,
356
+ resource_type="Database Right-sizing",
357
+ current_monthly_cost=monthly_cost,
358
+ potential_monthly_savings=db_rightsizing,
359
+ potential_annual_savings=db_rightsizing * 12,
360
+ confidence_level="MEDIUM",
361
+ priority_score=7,
362
+ implementation_complexity="COMPLEX",
363
+ risk_level="HIGH",
364
+ payback_period_months=2,
365
+ roi_percentage=20.0,
366
+ description="Right-size RDS instances based on performance metrics",
367
+ action_steps=[
368
+ "1. Enable Enhanced Monitoring for all RDS instances",
369
+ "2. Analyze CPU, memory, and I/O utilization for 30 days",
370
+ "3. Identify over-provisioned instances (<60% utilization)",
371
+ "4. Test smaller instance types in staging environment",
372
+ "5. Schedule maintenance windows for production changes",
373
+ ],
374
+ business_impact=f"Optimize database performance and costs by ${db_rightsizing:,.0f}/month",
375
+ resource_count=int(monthly_cost / 400 * 0.3),
376
+ )
377
+ )
378
+
379
+ total_potential = sum(rec.potential_monthly_savings for rec in recommendations)
380
+ optimization_percentage = (total_potential / monthly_cost * 100) if monthly_cost > 0 else 0
381
+
382
+ priority_actions = [
383
+ "🗄️ Analyze RDS Reserved Instance opportunities for production workloads",
384
+ "📊 Enable Enhanced Monitoring for performance analysis",
385
+ "⚡ Consider Aurora Serverless for variable workloads",
386
+ ]
387
+
388
+ return ServiceOptimizationResults(
389
+ service_name=service_name,
390
+ total_monthly_cost=monthly_cost,
391
+ total_potential_savings=total_potential,
392
+ recommendations=recommendations,
393
+ optimization_percentage=optimization_percentage,
394
+ priority_actions=priority_actions,
395
+ )
396
+
397
+ def _optimize_nat_gateway_recommendations(
398
+ self, service_name: str, monthly_cost: float, previous_cost: float
399
+ ) -> ServiceOptimizationResults:
400
+ """NAT Gateway-specific optimization recommendations"""
401
+ recommendations = []
402
+
403
+ if monthly_cost > 200:
404
+ # NAT Instance alternative
405
+ nat_instance_savings = monthly_cost * 0.60 # 60% savings with NAT instances
406
+ recommendations.append(
407
+ OptimizationRecommendation(
408
+ service_name=service_name,
409
+ resource_type="NAT Instance Migration",
410
+ current_monthly_cost=monthly_cost,
411
+ potential_monthly_savings=nat_instance_savings,
412
+ potential_annual_savings=nat_instance_savings * 12,
413
+ confidence_level="MEDIUM",
414
+ priority_score=6,
415
+ implementation_complexity="COMPLEX",
416
+ risk_level="MEDIUM",
417
+ payback_period_months=1,
418
+ roi_percentage=60.0,
419
+ description="Migrate from NAT Gateway to NAT Instances for cost optimization",
420
+ action_steps=[
421
+ "1. Assess current NAT Gateway usage and requirements",
422
+ "2. Design high-availability NAT instance architecture",
423
+ "3. Create auto-scaling NAT instance solution",
424
+ "4. Test failover and performance scenarios",
425
+ "5. Migrate during maintenance window with rollback plan",
426
+ ],
427
+ business_impact=f"Reduce networking costs by ${nat_instance_savings:,.0f}/month",
428
+ resource_count=int(monthly_cost / 45), # ~$45/month per NAT Gateway
429
+ )
430
+ )
431
+
432
+ # VPC Endpoint optimization
433
+ vpc_endpoint_savings = monthly_cost * 0.30 # 30% data transfer savings
434
+ recommendations.append(
435
+ OptimizationRecommendation(
436
+ service_name=service_name,
437
+ resource_type="VPC Endpoints",
438
+ current_monthly_cost=monthly_cost,
439
+ potential_monthly_savings=vpc_endpoint_savings,
440
+ potential_annual_savings=vpc_endpoint_savings * 12,
441
+ confidence_level="HIGH",
442
+ priority_score=7,
443
+ implementation_complexity="MODERATE",
444
+ risk_level="LOW",
445
+ payback_period_months=2,
446
+ roi_percentage=30.0,
447
+ description="Implement VPC Endpoints to reduce NAT Gateway data transfer",
448
+ action_steps=[
449
+ "1. Identify high-traffic AWS services (S3, DynamoDB, etc.)",
450
+ "2. Create VPC endpoints for frequently accessed services",
451
+ "3. Update route tables and security groups",
452
+ "4. Monitor data transfer cost reduction",
453
+ "5. Expand VPC endpoints to additional services",
454
+ ],
455
+ business_impact=f"Reduce data transfer costs by ${vpc_endpoint_savings:,.0f}/month",
456
+ resource_count=0,
457
+ )
458
+ )
459
+
460
+ total_potential = sum(rec.potential_monthly_savings for rec in recommendations)
461
+ optimization_percentage = (total_potential / monthly_cost * 100) if monthly_cost > 0 else 0
462
+
463
+ priority_actions = [
464
+ "🌐 Implement VPC Endpoints for AWS services to reduce data transfer",
465
+ "🔀 Evaluate NAT Instance alternative for high-traffic scenarios",
466
+ "📊 Monitor data transfer patterns for optimization opportunities",
467
+ ]
468
+
469
+ return ServiceOptimizationResults(
470
+ service_name=service_name,
471
+ total_monthly_cost=monthly_cost,
472
+ total_potential_savings=total_potential,
473
+ recommendations=recommendations,
474
+ optimization_percentage=optimization_percentage,
475
+ priority_actions=priority_actions,
476
+ )
477
+
478
+ def _optimize_lambda_recommendations(
479
+ self, service_name: str, monthly_cost: float, previous_cost: float
480
+ ) -> ServiceOptimizationResults:
481
+ """Lambda-specific optimization recommendations"""
482
+ recommendations = []
483
+
484
+ if monthly_cost > 100:
485
+ # Memory optimization
486
+ memory_savings = monthly_cost * 0.25 # 25% potential savings
487
+ recommendations.append(
488
+ OptimizationRecommendation(
489
+ service_name=service_name,
490
+ resource_type="Memory Optimization",
491
+ current_monthly_cost=monthly_cost,
492
+ potential_monthly_savings=memory_savings,
493
+ potential_annual_savings=memory_savings * 12,
494
+ confidence_level="HIGH",
495
+ priority_score=8,
496
+ implementation_complexity="SIMPLE",
497
+ risk_level="LOW",
498
+ payback_period_months=0,
499
+ roi_percentage=25.0,
500
+ description="Optimize Lambda memory allocation for cost and performance",
501
+ action_steps=[
502
+ "1. Enable AWS Lambda Power Tuning for all functions",
503
+ "2. Analyze CloudWatch metrics for memory utilization",
504
+ "3. Test different memory configurations",
505
+ "4. Implement optimal memory settings",
506
+ "5. Monitor performance and cost impact",
507
+ ],
508
+ business_impact=f"Optimize Lambda performance and costs by ${memory_savings:,.0f}/month",
509
+ resource_count=0,
510
+ )
511
+ )
512
+
513
+ total_potential = sum(rec.potential_monthly_savings for rec in recommendations)
514
+ optimization_percentage = (total_potential / monthly_cost * 100) if monthly_cost > 0 else 0
515
+
516
+ priority_actions = [
517
+ "⚡ Use AWS Lambda Power Tuning for memory optimization",
518
+ "📊 Monitor invocation patterns and duration metrics",
519
+ "🔄 Consider Provisioned Concurrency for consistent workloads",
520
+ ]
521
+
522
+ return ServiceOptimizationResults(
523
+ service_name=service_name,
524
+ total_monthly_cost=monthly_cost,
525
+ total_potential_savings=total_potential,
526
+ recommendations=recommendations,
527
+ optimization_percentage=optimization_percentage,
528
+ priority_actions=priority_actions,
529
+ )
530
+
531
+ def _optimize_cloudwatch_recommendations(
532
+ self, service_name: str, monthly_cost: float, previous_cost: float
533
+ ) -> ServiceOptimizationResults:
534
+ """CloudWatch-specific optimization recommendations"""
535
+ recommendations = []
536
+
537
+ if monthly_cost > 100:
538
+ # Log retention optimization
539
+ log_savings = monthly_cost * 0.40 # 40% potential savings
540
+ recommendations.append(
541
+ OptimizationRecommendation(
542
+ service_name=service_name,
543
+ resource_type="Log Retention Optimization",
544
+ current_monthly_cost=monthly_cost,
545
+ potential_monthly_savings=log_savings,
546
+ potential_annual_savings=log_savings * 12,
547
+ confidence_level="HIGH",
548
+ priority_score=7,
549
+ implementation_complexity="SIMPLE",
550
+ risk_level="LOW",
551
+ payback_period_months=0,
552
+ roi_percentage=40.0,
553
+ description="Optimize CloudWatch Logs retention policies",
554
+ action_steps=[
555
+ "1. Audit all CloudWatch Log Groups and retention settings",
556
+ "2. Define appropriate retention periods by log type",
557
+ "3. Update retention policies (30-90 days for most logs)",
558
+ "4. Archive critical logs to S3 for long-term retention",
559
+ "5. Monitor log ingestion costs monthly",
560
+ ],
561
+ business_impact=f"Reduce CloudWatch costs by ${log_savings:,.0f}/month",
562
+ resource_count=0,
563
+ )
564
+ )
565
+
566
+ total_potential = sum(rec.potential_monthly_savings for rec in recommendations)
567
+ optimization_percentage = (total_potential / monthly_cost * 100) if monthly_cost > 0 else 0
568
+
569
+ priority_actions = [
570
+ "📋 Review and optimize log retention policies",
571
+ "📊 Use CloudWatch Insights for log analysis efficiency",
572
+ "💾 Archive historical logs to S3 for compliance",
573
+ ]
574
+
575
+ return ServiceOptimizationResults(
576
+ service_name=service_name,
577
+ total_monthly_cost=monthly_cost,
578
+ total_potential_savings=total_potential,
579
+ recommendations=recommendations,
580
+ optimization_percentage=optimization_percentage,
581
+ priority_actions=priority_actions,
582
+ )
583
+
584
+ def _optimize_dynamodb_recommendations(
585
+ self, service_name: str, monthly_cost: float, previous_cost: float
586
+ ) -> ServiceOptimizationResults:
587
+ """DynamoDB-specific optimization recommendations"""
588
+ recommendations = []
589
+
590
+ if monthly_cost > 200:
591
+ # On-Demand vs Provisioned optimization
592
+ pricing_savings = monthly_cost * 0.25 # 25% potential savings
593
+ recommendations.append(
594
+ OptimizationRecommendation(
595
+ service_name=service_name,
596
+ resource_type="Pricing Model Optimization",
597
+ current_monthly_cost=monthly_cost,
598
+ potential_monthly_savings=pricing_savings,
599
+ potential_annual_savings=pricing_savings * 12,
600
+ confidence_level="MEDIUM",
601
+ priority_score=6,
602
+ implementation_complexity="MODERATE",
603
+ risk_level="MEDIUM",
604
+ payback_period_months=1,
605
+ roi_percentage=25.0,
606
+ description="Optimize DynamoDB pricing model (On-Demand vs Provisioned)",
607
+ action_steps=[
608
+ "1. Analyze read/write capacity utilization patterns",
609
+ "2. Compare On-Demand vs Provisioned costs for each table",
610
+ "3. Switch to Provisioned for predictable workloads",
611
+ "4. Use Auto Scaling for variable workloads",
612
+ "5. Monitor and adjust capacity settings monthly",
613
+ ],
614
+ business_impact=f"Optimize DynamoDB costs by ${pricing_savings:,.0f}/month",
615
+ resource_count=0,
616
+ )
617
+ )
618
+
619
+ total_potential = sum(rec.potential_monthly_savings for rec in recommendations)
620
+ optimization_percentage = (total_potential / monthly_cost * 100) if monthly_cost > 0 else 0
621
+
622
+ priority_actions = [
623
+ "📊 Analyze read/write patterns for pricing optimization",
624
+ "🔄 Enable Auto Scaling for Provisioned tables",
625
+ "💾 Consider DynamoDB Standard-IA for infrequent access data",
626
+ ]
627
+
628
+ return ServiceOptimizationResults(
629
+ service_name=service_name,
630
+ total_monthly_cost=monthly_cost,
631
+ total_potential_savings=total_potential,
632
+ recommendations=recommendations,
633
+ optimization_percentage=optimization_percentage,
634
+ priority_actions=priority_actions,
635
+ )
636
+
637
+ def _optimize_ebs_recommendations(
638
+ self, service_name: str, monthly_cost: float, previous_cost: float
639
+ ) -> ServiceOptimizationResults:
640
+ """EBS-specific optimization recommendations"""
641
+ recommendations = []
642
+
643
+ if monthly_cost > 300:
644
+ # EBS volume optimization
645
+ volume_savings = monthly_cost * 0.30 # 30% potential savings
646
+ recommendations.append(
647
+ OptimizationRecommendation(
648
+ service_name=service_name,
649
+ resource_type="Volume Type Optimization",
650
+ current_monthly_cost=monthly_cost,
651
+ potential_monthly_savings=volume_savings,
652
+ potential_annual_savings=volume_savings * 12,
653
+ confidence_level="HIGH",
654
+ priority_score=7,
655
+ implementation_complexity="MODERATE",
656
+ risk_level="LOW",
657
+ payback_period_months=1,
658
+ roi_percentage=30.0,
659
+ description="Optimize EBS volume types and eliminate unused volumes",
660
+ action_steps=[
661
+ "1. Identify unused and unattached EBS volumes",
662
+ "2. Analyze IOPS requirements vs volume types",
663
+ "3. Migrate gp2 to gp3 volumes for cost savings",
664
+ "4. Delete snapshots older than retention policy",
665
+ "5. Implement automated volume cleanup",
666
+ ],
667
+ business_impact=f"Reduce storage costs by ${volume_savings:,.0f}/month",
668
+ resource_count=int(monthly_cost / 8), # ~$8/month per 100GB gp3
669
+ )
670
+ )
671
+
672
+ total_potential = sum(rec.potential_monthly_savings for rec in recommendations)
673
+ optimization_percentage = (total_potential / monthly_cost * 100) if monthly_cost > 0 else 0
674
+
675
+ priority_actions = [
676
+ "💾 Migrate gp2 volumes to gp3 for immediate cost savings",
677
+ "🗑️ Clean up unused volumes and old snapshots",
678
+ "📊 Right-size volumes based on actual usage patterns",
679
+ ]
680
+
681
+ return ServiceOptimizationResults(
682
+ service_name=service_name,
683
+ total_monthly_cost=monthly_cost,
684
+ total_potential_savings=total_potential,
685
+ recommendations=recommendations,
686
+ optimization_percentage=optimization_percentage,
687
+ priority_actions=priority_actions,
688
+ )
689
+
690
+ def _optimize_data_transfer_recommendations(
691
+ self, service_name: str, monthly_cost: float, previous_cost: float
692
+ ) -> ServiceOptimizationResults:
693
+ """Data Transfer-specific optimization recommendations"""
694
+ recommendations = []
695
+
696
+ if monthly_cost > 500:
697
+ # CloudFront optimization
698
+ cdn_savings = monthly_cost * 0.50 # 50% potential savings
699
+ recommendations.append(
700
+ OptimizationRecommendation(
701
+ service_name=service_name,
702
+ resource_type="CloudFront CDN",
703
+ current_monthly_cost=monthly_cost,
704
+ potential_monthly_savings=cdn_savings,
705
+ potential_annual_savings=cdn_savings * 12,
706
+ confidence_level="HIGH",
707
+ priority_score=8,
708
+ implementation_complexity="MODERATE",
709
+ risk_level="LOW",
710
+ payback_period_months=1,
711
+ roi_percentage=50.0,
712
+ description="Implement CloudFront CDN to reduce data transfer costs",
713
+ action_steps=[
714
+ "1. Analyze data transfer patterns and geographic distribution",
715
+ "2. Configure CloudFront distributions for static content",
716
+ "3. Implement caching strategies for dynamic content",
717
+ "4. Optimize origin request patterns",
718
+ "5. Monitor CloudFront vs direct transfer costs",
719
+ ],
720
+ business_impact=f"Reduce data transfer costs by ${cdn_savings:,.0f}/month",
721
+ resource_count=0,
722
+ )
723
+ )
724
+
725
+ total_potential = sum(rec.potential_monthly_savings for rec in recommendations)
726
+ optimization_percentage = (total_potential / monthly_cost * 100) if monthly_cost > 0 else 0
727
+
728
+ priority_actions = [
729
+ "🌐 Implement CloudFront CDN for frequently accessed content",
730
+ "🔗 Use VPC Endpoints to avoid internet data transfer charges",
731
+ "📊 Monitor and optimize cross-region data transfer patterns",
732
+ ]
733
+
734
+ return ServiceOptimizationResults(
735
+ service_name=service_name,
736
+ total_monthly_cost=monthly_cost,
737
+ total_potential_savings=total_potential,
738
+ recommendations=recommendations,
739
+ optimization_percentage=optimization_percentage,
740
+ priority_actions=priority_actions,
741
+ )
742
+
743
+ def _optimize_savings_plans_recommendations(
744
+ self, service_name: str, monthly_cost: float, previous_cost: float
745
+ ) -> ServiceOptimizationResults:
746
+ """Savings Plans optimization recommendations"""
747
+ recommendations = []
748
+
749
+ if monthly_cost > 5000:
750
+ # Additional Savings Plans coverage
751
+ additional_savings = monthly_cost * 0.20 # 20% additional potential
752
+ recommendations.append(
753
+ OptimizationRecommendation(
754
+ service_name=service_name,
755
+ resource_type="Enhanced Savings Plans",
756
+ current_monthly_cost=monthly_cost,
757
+ potential_monthly_savings=additional_savings,
758
+ potential_annual_savings=additional_savings * 12,
759
+ confidence_level="HIGH",
760
+ priority_score=9,
761
+ implementation_complexity="SIMPLE",
762
+ risk_level="LOW",
763
+ payback_period_months=0,
764
+ roi_percentage=20.0,
765
+ description="Optimize Savings Plans coverage and commitment levels",
766
+ action_steps=[
767
+ "1. Analyze current Savings Plans utilization and coverage",
768
+ "2. Review Cost Explorer recommendations for additional plans",
769
+ "3. Consider EC2 Instance Savings Plans for specific workloads",
770
+ "4. Purchase additional Compute Savings Plans if coverage <80%",
771
+ "5. Monitor utilization and adjust future purchases",
772
+ ],
773
+ business_impact=f"Additional savings of ${additional_savings:,.0f}/month through optimized coverage",
774
+ resource_count=0,
775
+ )
776
+ )
777
+
778
+ total_potential = sum(rec.potential_monthly_savings for rec in recommendations)
779
+ optimization_percentage = (total_potential / monthly_cost * 100) if monthly_cost > 0 else 0
780
+
781
+ priority_actions = [
782
+ "📊 Review Savings Plans utilization and coverage regularly",
783
+ "💰 Consider 3-year commitments for stable long-term workloads",
784
+ "🔄 Use Cost Explorer recommendations for optimal planning",
785
+ ]
786
+
787
+ return ServiceOptimizationResults(
788
+ service_name=service_name,
789
+ total_monthly_cost=monthly_cost,
790
+ total_potential_savings=total_potential,
791
+ recommendations=recommendations,
792
+ optimization_percentage=optimization_percentage,
793
+ priority_actions=priority_actions,
794
+ )
795
+
796
+ def _generic_service_optimization(
797
+ self, service_name: str, monthly_cost: float, previous_cost: float
798
+ ) -> ServiceOptimizationResults:
799
+ """Generic optimization recommendations for services without specific strategies"""
800
+ recommendations = []
801
+
802
+ if monthly_cost > 100:
803
+ # General optimization
804
+ generic_savings = monthly_cost * 0.15 # 15% generic potential
805
+ recommendations.append(
806
+ OptimizationRecommendation(
807
+ service_name=service_name,
808
+ resource_type="General Optimization",
809
+ current_monthly_cost=monthly_cost,
810
+ potential_monthly_savings=generic_savings,
811
+ potential_annual_savings=generic_savings * 12,
812
+ confidence_level="MEDIUM",
813
+ priority_score=5,
814
+ implementation_complexity="MODERATE",
815
+ risk_level="MEDIUM",
816
+ payback_period_months=2,
817
+ roi_percentage=15.0,
818
+ description=f"Review {service_name} usage patterns and optimize configuration",
819
+ action_steps=[
820
+ "1. Review service usage patterns and metrics",
821
+ "2. Identify unused or underutilized resources",
822
+ "3. Optimize service configuration settings",
823
+ "4. Consider alternative pricing models if available",
824
+ "5. Monitor and adjust based on performance impact",
825
+ ],
826
+ business_impact=f"Potential optimization savings of ${generic_savings:,.0f}/month",
827
+ resource_count=0,
828
+ )
829
+ )
830
+
831
+ total_potential = sum(rec.potential_monthly_savings for rec in recommendations)
832
+ optimization_percentage = (total_potential / monthly_cost * 100) if monthly_cost > 0 else 0
833
+
834
+ priority_actions = [
835
+ f"📊 Analyze {service_name} usage patterns for optimization opportunities",
836
+ "🔍 Review AWS documentation for service-specific best practices",
837
+ "💡 Consider AWS Trusted Advisor recommendations",
838
+ ]
839
+
840
+ return ServiceOptimizationResults(
841
+ service_name=service_name,
842
+ total_monthly_cost=monthly_cost,
843
+ total_potential_savings=total_potential,
844
+ recommendations=recommendations,
845
+ optimization_percentage=optimization_percentage,
846
+ priority_actions=priority_actions,
847
+ )
848
+
849
+ def create_optimization_summary_table(self, optimization_results: List[ServiceOptimizationResults]) -> Table:
850
+ """Create a Rich table summarizing optimization opportunities across all services"""
851
+
852
+ table = Table(
853
+ title="💰 Comprehensive Optimization Opportunities",
854
+ show_header=True,
855
+ header_style="bold cyan",
856
+ show_lines=True,
857
+ )
858
+
859
+ table.add_column("Service", style="white", width=15)
860
+ table.add_column("Current Cost", style="yellow", width=12, justify="right")
861
+ table.add_column("Potential Savings", style="green", width=15, justify="right")
862
+ table.add_column("Optimization %", style="bright_green", width=12, justify="center")
863
+ table.add_column("Top Priority Action", style="cyan", width=40)
864
+
865
+ total_current = 0
866
+ total_savings = 0
867
+
868
+ # Sort by potential savings (highest first)
869
+ sorted_results = sorted(optimization_results, key=lambda x: x.total_potential_savings, reverse=True)
870
+
871
+ for result in sorted_results:
872
+ if result.total_potential_savings > 0: # Only show services with optimization potential
873
+ total_current += result.total_monthly_cost
874
+ total_savings += result.total_potential_savings
875
+
876
+ # Get the highest priority action
877
+ top_action = result.priority_actions[0] if result.priority_actions else "Review usage patterns"
878
+
879
+ table.add_row(
880
+ result.service_name,
881
+ f"${result.total_monthly_cost:,.0f}",
882
+ f"${result.total_potential_savings:,.0f}",
883
+ f"{result.optimization_percentage:.1f}%",
884
+ top_action,
885
+ )
886
+
887
+ # Add summary row
888
+ if total_current > 0:
889
+ overall_percentage = total_savings / total_current * 100
890
+ table.add_row(
891
+ "[bold]TOTAL[/bold]",
892
+ f"[bold]${total_current:,.0f}[/bold]",
893
+ f"[bold green]${total_savings:,.0f}[/bold green]",
894
+ f"[bold green]{overall_percentage:.1f}%[/bold green]",
895
+ f"[bold]Annual Potential: ${total_savings * 12:,.0f}[/bold]",
896
+ )
897
+
898
+ return table
899
+
900
+ def create_priority_recommendations_panel(self, optimization_results: List[ServiceOptimizationResults]) -> Panel:
901
+ """Create a Rich panel with top priority recommendations"""
902
+
903
+ # Collect all recommendations and sort by priority score and savings
904
+ all_recommendations = []
905
+ for result in optimization_results:
906
+ all_recommendations.extend(result.recommendations)
907
+
908
+ # Sort by priority score (highest first), then by savings
909
+ top_recommendations = sorted(
910
+ all_recommendations, key=lambda x: (x.priority_score, x.potential_monthly_savings), reverse=True
911
+ )[:10] # Top 10 recommendations
912
+
913
+ content = "[bold cyan]🎯 Top 10 Priority Optimization Actions[/bold cyan]\n\n"
914
+
915
+ for i, rec in enumerate(top_recommendations, 1):
916
+ priority_color = "red" if rec.priority_score >= 8 else "yellow" if rec.priority_score >= 6 else "green"
917
+ risk_emoji = "🔴" if rec.risk_level == "HIGH" else "🟡" if rec.risk_level == "MEDIUM" else "🟢"
918
+ complexity_emoji = (
919
+ "🔧"
920
+ if rec.implementation_complexity == "SIMPLE"
921
+ else "⚙️"
922
+ if rec.implementation_complexity == "MODERATE"
923
+ else "🛠️"
924
+ )
925
+
926
+ content += (
927
+ f"[bold {priority_color}]{i:2d}. {rec.description}[/bold {priority_color}]\n"
928
+ f" 💰 Monthly Savings: [green]${rec.potential_monthly_savings:,.0f}[/green] "
929
+ f"| 📅 ROI: [bright_green]{rec.roi_percentage:.0f}%[/bright_green] "
930
+ f"| {risk_emoji} Risk: {rec.risk_level} "
931
+ f"| {complexity_emoji} {rec.implementation_complexity}\n"
932
+ f" 🎯 Next Step: {rec.action_steps[0] if rec.action_steps else 'Review implementation plan'}\n\n"
933
+ )
934
+
935
+ return Panel(content, title="🚀 Implementation Roadmap", style="bright_cyan")
936
+
937
+
938
+ def create_enhanced_optimization_display(cost_data: Dict[str, float], profile: str = "default") -> None:
939
+ """
940
+ Create enhanced optimization display for the FinOps dashboard
941
+ """
942
+ console.print("\n[bold cyan]🔍 Advanced Cost Optimization Analysis[/bold cyan]")
943
+
944
+ # Initialize optimization engine
945
+ optimizer = AdvancedOptimizationEngine(profile)
946
+
947
+ # Analyze each service
948
+ optimization_results = []
949
+ for service_name, monthly_cost in cost_data.items():
950
+ if monthly_cost > 0: # Only analyze services with costs
951
+ result = optimizer.analyze_service_optimization(service_name, monthly_cost)
952
+ optimization_results.append(result)
953
+
954
+ # Display optimization summary table
955
+ if optimization_results:
956
+ summary_table = optimizer.create_optimization_summary_table(optimization_results)
957
+ console.print(summary_table)
958
+
959
+ # Display priority recommendations
960
+ priority_panel = optimizer.create_priority_recommendations_panel(optimization_results)
961
+ console.print(priority_panel)
962
+
963
+ # Calculate and display total business impact
964
+ total_monthly_savings = sum(result.total_potential_savings for result in optimization_results)
965
+ total_annual_savings = total_monthly_savings * 12
966
+
967
+ if total_monthly_savings > 0:
968
+ business_impact_panel = Panel.fit(
969
+ f"[bold green]💼 Total Business Impact[/bold green]\n\n"
970
+ f"💰 Monthly Optimization Potential: [yellow]${total_monthly_savings:,.0f}[/yellow]\n"
971
+ f"📅 Annual Savings Potential: [bright_green]${total_annual_savings:,.0f}[/bright_green]\n"
972
+ f"🎯 Implementation Priority: Start with highest ROI, lowest risk actions\n"
973
+ f"⏱️ Estimated Implementation Time: 2-6 weeks for top recommendations",
974
+ title="🚀 Executive Summary",
975
+ style="bright_green",
976
+ )
977
+ console.print(business_impact_panel)
978
+
979
+ else:
980
+ console.print("[yellow]📊 No significant optimization opportunities identified in current cost data[/yellow]")