runbooks 1.1.4__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 (228) 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/assessment/compliance.py +1 -1
  8. runbooks/cfat/assessment/runner.py +1 -0
  9. runbooks/cfat/cloud_foundations_assessment.py +227 -239
  10. runbooks/cli/__init__.py +1 -1
  11. runbooks/cli/commands/cfat.py +64 -23
  12. runbooks/cli/commands/finops.py +1005 -54
  13. runbooks/cli/commands/inventory.py +138 -35
  14. runbooks/cli/commands/operate.py +9 -36
  15. runbooks/cli/commands/security.py +42 -18
  16. runbooks/cli/commands/validation.py +432 -18
  17. runbooks/cli/commands/vpc.py +81 -17
  18. runbooks/cli/registry.py +22 -10
  19. runbooks/cloudops/__init__.py +20 -27
  20. runbooks/cloudops/base.py +96 -107
  21. runbooks/cloudops/cost_optimizer.py +544 -542
  22. runbooks/cloudops/infrastructure_optimizer.py +5 -4
  23. runbooks/cloudops/interfaces.py +224 -225
  24. runbooks/cloudops/lifecycle_manager.py +5 -4
  25. runbooks/cloudops/mcp_cost_validation.py +252 -235
  26. runbooks/cloudops/models.py +78 -53
  27. runbooks/cloudops/monitoring_automation.py +5 -4
  28. runbooks/cloudops/notebook_framework.py +177 -213
  29. runbooks/cloudops/security_enforcer.py +125 -159
  30. runbooks/common/accuracy_validator.py +11 -0
  31. runbooks/common/aws_pricing.py +349 -326
  32. runbooks/common/aws_pricing_api.py +211 -212
  33. runbooks/common/aws_profile_manager.py +40 -36
  34. runbooks/common/aws_utils.py +74 -79
  35. runbooks/common/business_logic.py +126 -104
  36. runbooks/common/cli_decorators.py +36 -60
  37. runbooks/common/comprehensive_cost_explorer_integration.py +455 -463
  38. runbooks/common/cross_account_manager.py +197 -204
  39. runbooks/common/date_utils.py +27 -39
  40. runbooks/common/decorators.py +29 -19
  41. runbooks/common/dry_run_examples.py +173 -208
  42. runbooks/common/dry_run_framework.py +157 -155
  43. runbooks/common/enhanced_exception_handler.py +15 -4
  44. runbooks/common/enhanced_logging_example.py +50 -64
  45. runbooks/common/enhanced_logging_integration_example.py +65 -37
  46. runbooks/common/env_utils.py +16 -16
  47. runbooks/common/error_handling.py +40 -38
  48. runbooks/common/lazy_loader.py +41 -23
  49. runbooks/common/logging_integration_helper.py +79 -86
  50. runbooks/common/mcp_cost_explorer_integration.py +476 -493
  51. runbooks/common/mcp_integration.py +63 -74
  52. runbooks/common/memory_optimization.py +140 -118
  53. runbooks/common/module_cli_base.py +37 -58
  54. runbooks/common/organizations_client.py +175 -193
  55. runbooks/common/patterns.py +23 -25
  56. runbooks/common/performance_monitoring.py +67 -71
  57. runbooks/common/performance_optimization_engine.py +283 -274
  58. runbooks/common/profile_utils.py +111 -37
  59. runbooks/common/rich_utils.py +201 -141
  60. runbooks/common/sre_performance_suite.py +177 -186
  61. runbooks/enterprise/__init__.py +1 -1
  62. runbooks/enterprise/logging.py +144 -106
  63. runbooks/enterprise/security.py +187 -204
  64. runbooks/enterprise/validation.py +43 -56
  65. runbooks/finops/__init__.py +26 -30
  66. runbooks/finops/account_resolver.py +1 -1
  67. runbooks/finops/advanced_optimization_engine.py +980 -0
  68. runbooks/finops/automation_core.py +268 -231
  69. runbooks/finops/business_case_config.py +184 -179
  70. runbooks/finops/cli.py +660 -139
  71. runbooks/finops/commvault_ec2_analysis.py +157 -164
  72. runbooks/finops/compute_cost_optimizer.py +336 -320
  73. runbooks/finops/config.py +20 -20
  74. runbooks/finops/cost_optimizer.py +484 -618
  75. runbooks/finops/cost_processor.py +332 -214
  76. runbooks/finops/dashboard_runner.py +1006 -172
  77. runbooks/finops/ebs_cost_optimizer.py +991 -657
  78. runbooks/finops/elastic_ip_optimizer.py +317 -257
  79. runbooks/finops/enhanced_mcp_integration.py +340 -0
  80. runbooks/finops/enhanced_progress.py +32 -29
  81. runbooks/finops/enhanced_trend_visualization.py +3 -2
  82. runbooks/finops/enterprise_wrappers.py +223 -285
  83. runbooks/finops/executive_export.py +203 -160
  84. runbooks/finops/helpers.py +130 -288
  85. runbooks/finops/iam_guidance.py +1 -1
  86. runbooks/finops/infrastructure/__init__.py +80 -0
  87. runbooks/finops/infrastructure/commands.py +506 -0
  88. runbooks/finops/infrastructure/load_balancer_optimizer.py +866 -0
  89. runbooks/finops/infrastructure/vpc_endpoint_optimizer.py +832 -0
  90. runbooks/finops/markdown_exporter.py +337 -174
  91. runbooks/finops/mcp_validator.py +1952 -0
  92. runbooks/finops/nat_gateway_optimizer.py +1512 -481
  93. runbooks/finops/network_cost_optimizer.py +657 -587
  94. runbooks/finops/notebook_utils.py +226 -188
  95. runbooks/finops/optimization_engine.py +1136 -0
  96. runbooks/finops/optimizer.py +19 -23
  97. runbooks/finops/rds_snapshot_optimizer.py +367 -411
  98. runbooks/finops/reservation_optimizer.py +427 -363
  99. runbooks/finops/scenario_cli_integration.py +64 -65
  100. runbooks/finops/scenarios.py +1277 -438
  101. runbooks/finops/schemas.py +218 -182
  102. runbooks/finops/snapshot_manager.py +2289 -0
  103. runbooks/finops/types.py +3 -3
  104. runbooks/finops/validation_framework.py +259 -265
  105. runbooks/finops/vpc_cleanup_exporter.py +189 -144
  106. runbooks/finops/vpc_cleanup_optimizer.py +591 -573
  107. runbooks/finops/workspaces_analyzer.py +171 -182
  108. runbooks/integration/__init__.py +89 -0
  109. runbooks/integration/mcp_integration.py +1920 -0
  110. runbooks/inventory/CLAUDE.md +816 -0
  111. runbooks/inventory/__init__.py +2 -2
  112. runbooks/inventory/cloud_foundations_integration.py +144 -149
  113. runbooks/inventory/collectors/aws_comprehensive.py +1 -1
  114. runbooks/inventory/collectors/aws_networking.py +109 -99
  115. runbooks/inventory/collectors/base.py +4 -0
  116. runbooks/inventory/core/collector.py +495 -313
  117. runbooks/inventory/drift_detection_cli.py +69 -96
  118. runbooks/inventory/inventory_mcp_cli.py +48 -46
  119. runbooks/inventory/list_rds_snapshots_aggregator.py +192 -208
  120. runbooks/inventory/mcp_inventory_validator.py +549 -465
  121. runbooks/inventory/mcp_vpc_validator.py +359 -442
  122. runbooks/inventory/organizations_discovery.py +55 -51
  123. runbooks/inventory/rich_inventory_display.py +33 -32
  124. runbooks/inventory/unified_validation_engine.py +278 -251
  125. runbooks/inventory/vpc_analyzer.py +732 -695
  126. runbooks/inventory/vpc_architecture_validator.py +293 -348
  127. runbooks/inventory/vpc_dependency_analyzer.py +382 -378
  128. runbooks/inventory/vpc_flow_analyzer.py +1 -1
  129. runbooks/main.py +49 -34
  130. runbooks/main_final.py +91 -60
  131. runbooks/main_minimal.py +22 -10
  132. runbooks/main_optimized.py +131 -100
  133. runbooks/main_ultra_minimal.py +7 -2
  134. runbooks/mcp/__init__.py +36 -0
  135. runbooks/mcp/integration.py +679 -0
  136. runbooks/monitoring/performance_monitor.py +9 -4
  137. runbooks/operate/dynamodb_operations.py +3 -1
  138. runbooks/operate/ec2_operations.py +145 -137
  139. runbooks/operate/iam_operations.py +146 -152
  140. runbooks/operate/networking_cost_heatmap.py +29 -8
  141. runbooks/operate/rds_operations.py +223 -254
  142. runbooks/operate/s3_operations.py +107 -118
  143. runbooks/operate/vpc_operations.py +646 -616
  144. runbooks/remediation/base.py +1 -1
  145. runbooks/remediation/commons.py +10 -7
  146. runbooks/remediation/commvault_ec2_analysis.py +70 -66
  147. runbooks/remediation/ec2_unattached_ebs_volumes.py +1 -0
  148. runbooks/remediation/multi_account.py +24 -21
  149. runbooks/remediation/rds_snapshot_list.py +86 -60
  150. runbooks/remediation/remediation_cli.py +92 -146
  151. runbooks/remediation/universal_account_discovery.py +83 -79
  152. runbooks/remediation/workspaces_list.py +46 -41
  153. runbooks/security/__init__.py +19 -0
  154. runbooks/security/assessment_runner.py +1150 -0
  155. runbooks/security/baseline_checker.py +812 -0
  156. runbooks/security/cloudops_automation_security_validator.py +509 -535
  157. runbooks/security/compliance_automation_engine.py +17 -17
  158. runbooks/security/config/__init__.py +2 -2
  159. runbooks/security/config/compliance_config.py +50 -50
  160. runbooks/security/config_template_generator.py +63 -76
  161. runbooks/security/enterprise_security_framework.py +1 -1
  162. runbooks/security/executive_security_dashboard.py +519 -508
  163. runbooks/security/multi_account_security_controls.py +959 -1210
  164. runbooks/security/real_time_security_monitor.py +422 -444
  165. runbooks/security/security_baseline_tester.py +1 -1
  166. runbooks/security/security_cli.py +143 -112
  167. runbooks/security/test_2way_validation.py +439 -0
  168. runbooks/security/two_way_validation_framework.py +852 -0
  169. runbooks/sre/production_monitoring_framework.py +167 -177
  170. runbooks/tdd/__init__.py +15 -0
  171. runbooks/tdd/cli.py +1071 -0
  172. runbooks/utils/__init__.py +14 -17
  173. runbooks/utils/logger.py +7 -2
  174. runbooks/utils/version_validator.py +50 -47
  175. runbooks/validation/__init__.py +6 -6
  176. runbooks/validation/cli.py +9 -3
  177. runbooks/validation/comprehensive_2way_validator.py +745 -704
  178. runbooks/validation/mcp_validator.py +906 -228
  179. runbooks/validation/terraform_citations_validator.py +104 -115
  180. runbooks/validation/terraform_drift_detector.py +447 -451
  181. runbooks/vpc/README.md +617 -0
  182. runbooks/vpc/__init__.py +8 -1
  183. runbooks/vpc/analyzer.py +577 -0
  184. runbooks/vpc/cleanup_wrapper.py +476 -413
  185. runbooks/vpc/cli_cloudtrail_commands.py +339 -0
  186. runbooks/vpc/cli_mcp_validation_commands.py +480 -0
  187. runbooks/vpc/cloudtrail_audit_integration.py +717 -0
  188. runbooks/vpc/config.py +92 -97
  189. runbooks/vpc/cost_engine.py +411 -148
  190. runbooks/vpc/cost_explorer_integration.py +553 -0
  191. runbooks/vpc/cross_account_session.py +101 -106
  192. runbooks/vpc/enhanced_mcp_validation.py +917 -0
  193. runbooks/vpc/eni_gate_validator.py +961 -0
  194. runbooks/vpc/heatmap_engine.py +185 -160
  195. runbooks/vpc/mcp_no_eni_validator.py +680 -639
  196. runbooks/vpc/nat_gateway_optimizer.py +358 -0
  197. runbooks/vpc/networking_wrapper.py +15 -8
  198. runbooks/vpc/pdca_remediation_planner.py +528 -0
  199. runbooks/vpc/performance_optimized_analyzer.py +219 -231
  200. runbooks/vpc/runbooks_adapter.py +1167 -241
  201. runbooks/vpc/tdd_red_phase_stubs.py +601 -0
  202. runbooks/vpc/test_data_loader.py +358 -0
  203. runbooks/vpc/tests/conftest.py +314 -4
  204. runbooks/vpc/tests/test_cleanup_framework.py +1022 -0
  205. runbooks/vpc/tests/test_cost_engine.py +0 -2
  206. runbooks/vpc/topology_generator.py +326 -0
  207. runbooks/vpc/unified_scenarios.py +1297 -1124
  208. runbooks/vpc/vpc_cleanup_integration.py +1943 -1115
  209. runbooks-1.1.5.dist-info/METADATA +328 -0
  210. {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/RECORD +214 -193
  211. runbooks/finops/README.md +0 -414
  212. runbooks/finops/accuracy_cross_validator.py +0 -647
  213. runbooks/finops/business_cases.py +0 -950
  214. runbooks/finops/dashboard_router.py +0 -922
  215. runbooks/finops/ebs_optimizer.py +0 -973
  216. runbooks/finops/embedded_mcp_validator.py +0 -1629
  217. runbooks/finops/enhanced_dashboard_runner.py +0 -527
  218. runbooks/finops/finops_dashboard.py +0 -584
  219. runbooks/finops/finops_scenarios.py +0 -1218
  220. runbooks/finops/legacy_migration.py +0 -730
  221. runbooks/finops/multi_dashboard.py +0 -1519
  222. runbooks/finops/single_dashboard.py +0 -1113
  223. runbooks/finops/unlimited_scenarios.py +0 -393
  224. runbooks-1.1.4.dist-info/METADATA +0 -800
  225. {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/WHEEL +0 -0
  226. {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/entry_points.txt +0 -0
  227. {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/licenses/LICENSE +0 -0
  228. {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/top_level.txt +0 -0
runbooks/vpc/README.md CHANGED
@@ -69,6 +69,7 @@ Key capabilities include:
69
69
  - Centralized configuration via TOML files
70
70
  - Environment-specific settings
71
71
  - Profile-based authentication management
72
+ - **NEW**: YAML campaign configuration for multi-Landing Zone VPC cleanup analysis
72
73
  - **Rich Terminal UI**: Beautiful terminal output with progress indicators and charts
73
74
  - **Export Options**:
74
75
  - JSON export for automation integration
@@ -246,6 +247,622 @@ runbooks vpc cleanup --dry-run --profile production
246
247
  runbooks vpc analyze --utilization --profile production
247
248
  ```
248
249
 
250
+ ### **NEW: Config-Driven VPC Cleanup Campaign Analysis**
251
+
252
+ **AWS-25 Campaign Example** ($101,247.67/year realized savings):
253
+
254
+ ```bash
255
+ # Config-driven multi-VPC cleanup analysis
256
+ runbooks vpc analyze \
257
+ --config examples/vpc-cleanup/aws25-campaign-config.yaml \
258
+ --profile ams-admin-Billing-ReadOnlyAccess-909135376185
259
+ ```
260
+
261
+ **Campaign Results Output**:
262
+ ```
263
+ ╭─ VPC Cleanup Campaign: AWS-25 ─────────────────────────╮
264
+ │ AWS Profile: ams-admin-Billing-ReadOnlyAccess-909135376185 │
265
+ │ VPCs Analyzed: 6 │
266
+ │ Accounts: 909135376185, 335083429030 │
267
+ │ Regions: ap-southeast-2 │
268
+ ╰─────────────────────────────────────────────────────────╯
269
+
270
+ ╭─ Campaign Results ──────────────────────────────────────╮
271
+ │ VPC ID Account Deletion Annual │
272
+ │ Date Savings │
273
+ ├─────────────────────────────────────────────────────────┤
274
+ │ vpc-0e113622eb4... 909135376185 2025-09-10 $0.00 │
275
+ │ vpc-090b313795... 909135376185 2025-09-08 $0.00 │
276
+ │ vpc-016a2f1e86... 909135376185 2025-08-04 $88,215.38 │
277
+ │ vpc-08df1f9529... 335083429030 2025-09-10 $241.53 │
278
+ │ vpc-0eabfc3260... 335083429030 2025-09-08 $110.65 │
279
+ │ vpc-0f1a336ec8... 335083429030 2025-08-04 $12,680.11 │
280
+ ╰─────────────────────────────────────────────────────────╯
281
+
282
+ ✓ Total Campaign Savings: $101,247.67/year
283
+ ```
284
+
285
+ **Campaign Config Schema** (YAML):
286
+ ```yaml
287
+ campaign_metadata:
288
+ campaign_id: "AWS-25"
289
+ aws_billing_profile: "ams-admin-Billing-ReadOnlyAccess-909135376185"
290
+
291
+ deleted_vpcs:
292
+ - vpc_id: "vpc-0e113622eb492c654"
293
+ account_id: "909135376185"
294
+ region: "ap-southeast-2"
295
+ deletion_date: "2025-09-10"
296
+
297
+ cost_explorer_config:
298
+ metrics: ["UnblendedCost"]
299
+ granularity_monthly: "MONTHLY"
300
+
301
+ attribution_rules:
302
+ vpc_specific_services:
303
+ attribution_percentage: 100
304
+ confidence_level: "HIGH (95%)"
305
+ ```
306
+
307
+ **Multi-Landing Zone Deployment**:
308
+ ```bash
309
+ # Create custom campaign config
310
+ cp examples/vpc-cleanup/aws25-campaign-config.yaml config/my_lz_config.yaml
311
+
312
+ # Update VPC list and campaign metadata
313
+ vim config/my_lz_config.yaml
314
+
315
+ # Execute analysis
316
+ runbooks vpc analyze --config config/my_lz_config.yaml --profile my-billing-profile
317
+ ```
318
+
319
+ ---
320
+
321
+ ## Multi-Landing Zone Deployment Patterns
322
+
323
+ ### Deployment Patterns Overview
324
+
325
+ #### Pattern Comparison Matrix
326
+
327
+ | Pattern | Use Case | Complexity | VPC Count | Account Count | Execution Time |
328
+ |---------|----------|------------|-----------|---------------|----------------|
329
+ | **Single-Account LZ** | Single AWS account cleanup | Low | 1-10 | 1 | 5-15 min |
330
+ | **Multi-Account Org** | AWS Organizations cleanup | Medium | 10-50 | 3-20 | 30-90 min |
331
+ | **Custom Attribution** | Fine-tuned confidence rules | Medium | Any | Any | Same as base |
332
+ | **Large-Scale LZ** | Enterprise-wide cleanup | High | 50+ | 20+ | 2-4 hours |
333
+
334
+ ---
335
+
336
+ ### Pattern 1: Single-Account Landing Zone
337
+
338
+ **Use Case**: Single AWS account with multiple VPCs deleted over time period.
339
+
340
+ **Typical Scenarios**:
341
+ - Dev/Test account cleanup
342
+ - Single-account sandbox decommission
343
+ - Departmental AWS account cleanup
344
+
345
+ #### Prerequisites
346
+
347
+ **Identify Deleted VPCs via CloudTrail**:
348
+ ```bash
349
+ # Query CloudTrail for DeleteVpc events
350
+ AWS_PROFILE=account-profile aws cloudtrail lookup-events \
351
+ --lookup-attributes AttributeKey=EventName,AttributeValue=DeleteVpc \
352
+ --start-time "2025-07-01" \
353
+ --end-time "2025-10-01"
354
+ ```
355
+
356
+ **MCP Alternative**:
357
+ ```bash
358
+ # Using MCP CloudTrail tool
359
+ mcp__cloudtrail__lookup_events \
360
+ --attribute-key EventName \
361
+ --attribute-value DeleteVpc \
362
+ --start-time "30 days ago"
363
+ ```
364
+
365
+ #### Deployment Steps
366
+
367
+ **Create Campaign Config**:
368
+ ```yaml
369
+ # config/lz_acme_dev_config.yaml
370
+ campaign_metadata:
371
+ campaign_id: "LZ-ACME-DEV-Q3-2025"
372
+ campaign_name: "ACME Dev Account VPC Cleanup - Q3 2025"
373
+ aws_billing_profile: "acme-dev-billing-readonly"
374
+
375
+ deleted_vpcs:
376
+ - vpc_id: "vpc-0abc123def456789a"
377
+ account_id: "123456789012"
378
+ deletion_date: "2025-09-15"
379
+ deletion_principal: "devops-team@acme.com"
380
+ pre_deletion_baseline_months: 3
381
+
382
+ cost_explorer_config:
383
+ metrics: ["UnblendedCost"]
384
+ pre_deletion_baseline:
385
+ granularity_monthly: "MONTHLY"
386
+ months_before_deletion: 3
387
+ post_deletion_validation:
388
+ days_after_deletion: 30
389
+
390
+ attribution_rules:
391
+ vpc_specific_services:
392
+ confidence_level: "HIGH (95%)"
393
+ attribution_percentage: 100
394
+ service_patterns: ["Amazon Virtual Private Cloud", "AWS PrivateLink"]
395
+ vpc_related_services:
396
+ confidence_level: "MEDIUM (85%)"
397
+ attribution_percentage: 70
398
+ service_patterns: ["Amazon Elastic Compute Cloud - Compute"]
399
+ ```
400
+
401
+ **Execute Analysis**:
402
+ ```bash
403
+ ./run_vpc_savings_analysis.sh ../config/lz_acme_dev_config.yaml
404
+ ```
405
+
406
+ ---
407
+
408
+ ### Pattern 2: Multi-Account Organization
409
+
410
+ **Use Case**: AWS Organizations with VPCs deleted across multiple member accounts.
411
+
412
+ **Typical Scenarios**:
413
+ - Organization-wide quarterly cleanup
414
+ - Multi-account migration completion
415
+ - Cross-account infrastructure decommission
416
+
417
+ #### Prerequisites
418
+ 1. **Centralized Billing Account**: Master payer with Cost Explorer enabled
419
+ 2. **Multi-Account CloudTrail**: Query across all member accounts
420
+ 3. **IAM Permissions**: Read-only Cost Explorer in master account
421
+
422
+ #### Deployment Steps
423
+
424
+ **Query CloudTrail Across Organization**:
425
+ ```bash
426
+ # Query each account for VPC deletions
427
+ for profile in billing-account ops-account dev-account; do
428
+ AWS_PROFILE=$profile aws cloudtrail lookup-events \
429
+ --lookup-attributes AttributeKey=EventName,AttributeValue=DeleteVpc \
430
+ --start-time "2025-07-01"
431
+ done > vpc_deletions_org_wide.json
432
+ ```
433
+
434
+ **Create Multi-Account Config**:
435
+ ```yaml
436
+ # config/org_q3_cleanup_config.yaml
437
+ campaign_metadata:
438
+ campaign_id: "ORG-WIDE-CLEANUP-Q3-2025"
439
+ aws_billing_profile: "org-master-billing-readonly"
440
+
441
+ deleted_vpcs:
442
+ # Operations Account VPCs
443
+ - vpc_id: "vpc-ops-001-primary"
444
+ account_id: "111111111111"
445
+ deletion_date: "2025-08-10"
446
+
447
+ # Development Account VPCs
448
+ - vpc_id: "vpc-dev-001-sandbox"
449
+ account_id: "222222222222"
450
+ deletion_date: "2025-08-15"
451
+
452
+ # Production Account VPCs
453
+ - vpc_id: "vpc-prod-legacy-001"
454
+ account_id: "444444444444"
455
+ deletion_date: "2025-09-05"
456
+ pre_deletion_baseline_months: 6 # Longer baseline for prod
457
+ ```
458
+
459
+ **Execute with Organization Billing**:
460
+ ```bash
461
+ ./run_vpc_savings_analysis.sh ../config/org_q3_cleanup_config.yaml
462
+ ```
463
+
464
+ **Analyze Consolidated Results**:
465
+ ```bash
466
+ # Calculate total savings by account
467
+ awk -F',' 'NR>1 {sum[$2]+=$(NF-5)} END {for (acct in sum) print acct, sum[acct]}' \
468
+ ../artifacts/org_q3_vpc_cleanup_savings.csv
469
+ ```
470
+
471
+ **Expected Output**:
472
+ ```
473
+ 111111111111 $15,234.56/year (Ops Account)
474
+ 222222222222 $23,456.78/year (Dev Account)
475
+ 444444444444 $45,678.90/year (Prod Account)
476
+ ---
477
+ Total: $93,271.47/year
478
+ ```
479
+
480
+ ---
481
+
482
+ ### Pattern 3: Custom Attribution Rules
483
+
484
+ **Use Case**: Adjust attribution percentages for specific environments.
485
+
486
+ #### Scenario A: Single-VPC Account (Higher Confidence)
487
+
488
+ **Rationale**: When account only had one VPC, attribution more accurate.
489
+
490
+ ```yaml
491
+ attribution_rules:
492
+ vpc_specific_services:
493
+ confidence_level: "HIGH (98%)"
494
+ attribution_percentage: 100
495
+ vpc_related_services:
496
+ confidence_level: "MEDIUM (90%)"
497
+ attribution_percentage: 85 # Increased from default 70%
498
+ other_services:
499
+ confidence_level: "MEDIUM (85%)"
500
+ attribution_percentage: 50 # Increased from default 30%
501
+ ```
502
+
503
+ #### Scenario B: Kubernetes/EKS Cluster Cleanup
504
+
505
+ **Rationale**: EKS workloads have most services VPC-bound.
506
+
507
+ ```yaml
508
+ attribution_rules:
509
+ vpc_related_services:
510
+ confidence_level: "HIGH (92%)"
511
+ attribution_percentage: 90 # Higher for EKS
512
+ service_patterns:
513
+ - "Amazon Elastic Compute Cloud - Compute"
514
+ - "Amazon Elastic Container Service for Kubernetes"
515
+ - "Amazon EKS"
516
+ ```
517
+
518
+ #### Scenario C: Data Processing Workload (S3-Heavy)
519
+
520
+ **Rationale**: S3 data lake workloads have high non-VPC costs.
521
+
522
+ ```yaml
523
+ attribution_rules:
524
+ other_services:
525
+ confidence_level: "LOW (<75%)"
526
+ attribution_percentage: 15 # Lower - S3 costs not VPC-related
527
+ ```
528
+
529
+ ---
530
+
531
+ ### Best Practices
532
+
533
+ #### 1. Config Organization
534
+ ```
535
+ config/
536
+ ├── aws25_campaign_config.yaml # Reference template
537
+ ├── lz_dev_q3_2025_config.yaml # Dev account Q3
538
+ ├── lz_prod_q3_2025_config.yaml # Prod account Q3
539
+ └── org_wide_q3_2025_config.yaml # Organization-wide
540
+ ```
541
+
542
+ #### 2. Naming Conventions
543
+ - **Campaign ID**: `[SCOPE]-[NAME]-[TIME]` (e.g., `LZ-ACME-DEV-Q3-2025`)
544
+ - **Config File**: `[lz]_[account]_[period]_config.yaml`
545
+ - **Output File**: `[campaign_id]_savings.csv`
546
+
547
+ #### 3. Attribution Tuning
548
+ - **Single-VPC Accounts**: Increase attribution percentages (85% → 90%)
549
+ - **Multi-VPC Accounts**: Keep conservative defaults (70%, 30%)
550
+ - **EKS Clusters**: Increase vpc_related to 90%
551
+ - **S3-Heavy Workloads**: Decrease other_services to 15%
552
+
553
+ ---
554
+
555
+ ## Troubleshooting
556
+
557
+ ### Cost Explorer Issues
558
+
559
+ #### Issue: VPC Not in Cost Explorer Results
560
+
561
+ **Symptom**: `$0.00` savings for VPCs known to have costs.
562
+
563
+ **Root Cause**: Cost Explorer provides account-level costs, cannot filter by VPC ID.
564
+
565
+ **Explanation**:
566
+
567
+ AWS Cost Explorer API does **not** support filtering by VPC ID. The framework uses:
568
+
569
+ 1. **Account-level cost aggregation**: Total costs for entire AWS account
570
+ 2. **Service-based filtering**: Costs grouped by AWS service (EC2, VPC, ELB, etc.)
571
+ 3. **Conservative attribution methodology**: Infer VPC-specific costs from service patterns
572
+
573
+ **Attribution Methodology**:
574
+
575
+ | Service Category | Attribution % | Confidence | Logic |
576
+ |------------------|---------------|------------|-------|
577
+ | **VPC-specific** (Amazon VPC, PrivateLink) | 100% | HIGH (95%) | Directly attributable to VPC |
578
+ | **VPC-related** (EC2, ELB, Lambda) | 70% | MEDIUM (85%) | Likely VPC-related |
579
+ | **Other services** (S3, DynamoDB, etc.) | 30% | LOW (<85%) | May be VPC-related |
580
+
581
+ **Solution**: Results are lower-bound estimates. Review `Service_Analysis` column in CSV for breakdown.
582
+
583
+ ---
584
+
585
+ #### Issue: Cost Explorer Data Retention Limit
586
+
587
+ **Error**:
588
+ ```
589
+ ERROR: Cost data not available for date 2024-06-15
590
+ Cost Explorer retention: 13 months (395 days)
591
+ ```
592
+
593
+ **Root Cause**: VPC deletion date older than Cost Explorer retention window.
594
+
595
+ **Cost Explorer Retention**: 13 months (395 days) from current date
596
+
597
+ **Solution**:
598
+
599
+ **Check Deletion Date**:
600
+ ```bash
601
+ # Calculate days since deletion
602
+ deletion_date="2024-06-15"
603
+ current_date=$(date +%Y-%m-%d)
604
+ days_diff=$(( ($(date -jf "%Y-%m-%d" "$current_date" +%s) - $(date -jf "%Y-%m-%d" "$deletion_date" +%s)) / 86400 ))
605
+
606
+ echo "Days since deletion: $days_diff"
607
+ echo "Cost Explorer retention: 395 days"
608
+
609
+ if [ $days_diff -gt 395 ]; then
610
+ echo "ERROR: Deletion date too old for Cost Explorer"
611
+ else
612
+ echo "OK: Within Cost Explorer retention window"
613
+ fi
614
+ ```
615
+
616
+ **Alternative Data Sources**:
617
+ - AWS Cost and Usage Reports (CUR) - 12-month+ retention
618
+ - CloudWatch Metrics - 15-month retention
619
+ - S3 exported billing reports
620
+
621
+ ---
622
+
623
+ #### Issue: No Post-Deletion Data Available
624
+
625
+ **Error**:
626
+ ```
627
+ WARNING: No post-deletion data available for vpc-abc123
628
+ VPC deleted 5 days ago, framework requires 30 days post-deletion
629
+ ```
630
+
631
+ **Root Cause**: VPC deleted too recently for post-deletion analysis.
632
+
633
+ **Post-Deletion Requirements**:
634
+ - Default: 30 days of post-deletion data
635
+ - Minimum: 7 days for initial analysis
636
+
637
+ **Solution Options**:
638
+
639
+ **Option 1**: Adjust config to use fewer post-deletion days:
640
+ ```yaml
641
+ cost_explorer_config:
642
+ post_deletion_validation:
643
+ granularity_daily: "DAILY"
644
+ days_after_deletion: 7 # Reduced from 30
645
+ ```
646
+
647
+ **Option 2**: Wait until sufficient post-deletion data available.
648
+
649
+ **Option 3**: Run preliminary analysis, re-run after 30 days:
650
+ ```bash
651
+ # Preliminary analysis (7 days post-deletion)
652
+ python3 execute_cost_queries_boto3.py --config ../config/recent_deletion_config.yaml
653
+
654
+ # Re-run after 30 days (more accurate)
655
+ python3 execute_cost_queries_boto3.py --config ../config/recent_deletion_config.yaml
656
+ ```
657
+
658
+ ---
659
+
660
+ #### Issue: Cost Explorer Rate Limiting
661
+
662
+ **Error**:
663
+ ```
664
+ ERROR: ThrottlingException - Rate exceeded for Cost Explorer API
665
+ ```
666
+
667
+ **Root Cause**: Exceeded AWS Cost Explorer API rate limit (~5 requests/second).
668
+
669
+ **Framework Rate Limiting**: 0.3 seconds between queries (default).
670
+
671
+ **Solution**:
672
+
673
+ **Option 1**: Framework automatically handles rate limiting with delays.
674
+
675
+ **Option 2**: Increase delay in code:
676
+ ```python
677
+ # In execute_cost_queries_boto3.py
678
+ RATE_LIMIT_DELAY = 0.5 # Increase from 0.3 to 0.5 seconds
679
+ ```
680
+
681
+ **Option 3**: Retry after delay:
682
+ ```bash
683
+ # If execution fails due to rate limiting
684
+ sleep 60 # Wait 1 minute
685
+ ./run_vpc_savings_analysis.sh ../config/aws25_campaign_config.yaml
686
+ ```
687
+
688
+ ---
689
+
690
+ ### Low Confidence Results
691
+
692
+ #### Issue: All VPCs Marked LOW Confidence (<85%)
693
+
694
+ **Symptom**: All VPCs in CSV have `LOW (<85%)` confidence level.
695
+
696
+ **Root Cause**: Multi-VPC accounts or increased post-deletion activity.
697
+
698
+ **Common Scenarios**:
699
+
700
+ 1. **Multi-VPC Account**: Account has/had multiple VPCs, difficult to attribute costs to specific VPC
701
+ 2. **Post-Deletion Activity Increase**: New infrastructure provisioned after VPC deletion
702
+ 3. **Baseline Variability**: High cost fluctuation during pre-deletion period
703
+
704
+ **Review Notes Column**:
705
+ ```csv
706
+ VPC_ID,Confidence_Level,Notes
707
+ vpc-abc123,LOW (<85%),"Multi-VPC account, other VPCs active during baseline"
708
+ vpc-def456,LOW (<85%),"Post-deletion costs increased (new EC2 instances launched)"
709
+ vpc-ghi789,LOW (<85%),"High baseline variability, seasonality detected"
710
+ ```
711
+
712
+ **Solution Options**:
713
+
714
+ **Option 1**: Accept LOW confidence as lower-bound estimate.
715
+
716
+ **Option 2**: Cross-validate with CloudWatch metrics:
717
+ ```bash
718
+ # Check EC2 instance count trend
719
+ AWS_PROFILE=your-profile aws cloudwatch get-metric-statistics \
720
+ --namespace AWS/EC2 \
721
+ --metric-name InstanceCount \
722
+ --start-time 2025-07-01T00:00:00Z \
723
+ --end-time 2025-10-01T00:00:00Z \
724
+ --period 86400 \
725
+ --statistics Average
726
+ ```
727
+
728
+ **Option 3**: Manual validation with billing team for specific services.
729
+
730
+ ---
731
+
732
+ #### Issue: VPC Deletion Savings Negative
733
+
734
+ **Symptom**: `Monthly_Savings_Realized: -$500.00` (negative savings).
735
+
736
+ **Root Cause**: Costs increased after VPC deletion.
737
+
738
+ **Common Scenarios**:
739
+
740
+ 1. **New Infrastructure**: New resources provisioned post-deletion
741
+ 2. **Cost Migration**: Costs migrated to other VPCs/accounts
742
+ 3. **Baseline Noise**: Pre-deletion baseline was unusually low
743
+
744
+ **Framework Logic**: Reports negative savings (no zero-clamping).
745
+
746
+ **CSV Example**:
747
+ ```csv
748
+ VPC_ID,Pre_Deletion_Monthly_Avg,Post_Deletion_Monthly_Avg,Monthly_Savings_Realized,Notes
749
+ vpc-abc123,$1000.00,$1500.00,-$500.00,"Costs increased post-deletion, new EC2 instances"
750
+ ```
751
+
752
+ **Solution**:
753
+
754
+ 1. **Review Service_Analysis Column**: Identify which services increased.
755
+ 2. **Check CloudTrail for New Resources**: Post-deletion resource creation.
756
+ 3. **Exclude from Savings Report**: Negative savings indicate no VPC-related savings.
757
+
758
+ ---
759
+
760
+ ### VPC Not Found in Results
761
+
762
+ #### Issue: VPC Missing from CSV Output
763
+
764
+ **Symptom**: Expected 6 VPCs, only 5 in CSV.
765
+
766
+ **Root Cause**: Query failed for specific VPC or cost data unavailable.
767
+
768
+ **Solution**:
769
+
770
+ **Check Logs/Console Output** for errors:
771
+ ```bash
772
+ ./run_vpc_savings_analysis.sh ../config/aws25_campaign_config.yaml 2>&1 | tee execution.log
773
+
774
+ # Search for errors
775
+ grep -i "error\|warning" execution.log
776
+ ```
777
+
778
+ **Check JSON Results**:
779
+ ```bash
780
+ # View raw Cost Explorer results
781
+ cat ../artifacts/cost_explorer_results.json | jq '.vpc_queries[] | select(.vpc_id == "vpc-abc123")'
782
+ ```
783
+
784
+ **Verify VPC Deletion Date**:
785
+ ```bash
786
+ # Query CloudTrail for exact deletion event
787
+ AWS_PROFILE=your-profile aws cloudtrail lookup-events \
788
+ --lookup-attributes AttributeKey=ResourceName,AttributeValue=vpc-abc123
789
+ ```
790
+
791
+ ---
792
+
793
+ ### Common Error Messages Reference
794
+
795
+ | Error Message | Cause | Solution |
796
+ |---------------|-------|----------|
797
+ | `AccessDeniedException` | No Cost Explorer permissions | Add IAM policy with ce:GetCostAndUsage |
798
+ | `NoCredentialsError` | AWS credentials not configured | Configure AWS profile |
799
+ | `InvalidVpcId` | VPC ID format invalid | Use vpc-* format |
800
+ | `ThrottlingException` | API rate limit exceeded | Framework retries automatically |
801
+ | `ValidationError` | YAML schema validation failed | Check required fields |
802
+ | `ExpiredTokenException` | STS credentials expired | Re-authenticate |
803
+
804
+ ---
805
+
806
+ ## Configuration Reference
807
+
808
+ ### CLI Parameters
809
+
810
+ #### All Scripts Accept
811
+
812
+ | Parameter | Description | Default |
813
+ |-----------|-------------|---------|
814
+ | `--config` | Path to campaign config YAML | `../config/aws25_campaign_config.yaml` |
815
+ | `--profile` | AWS profile override | From config `aws_billing_profile` |
816
+ | `--output-dir` | Output directory override | `../artifacts/` |
817
+
818
+ #### Script-Specific Parameters
819
+
820
+ **execute_cost_queries_boto3.py**:
821
+ - `--skip-queries`: Skip query execution, analyze existing results
822
+
823
+ **run_vpc_savings_analysis.sh**:
824
+ - First argument: Config file path (optional)
825
+ - Second argument: AWS profile override (optional)
826
+
827
+ ---
828
+
829
+ ### Advanced Configuration Examples
830
+
831
+ #### Custom Attribution Rules
832
+
833
+ Fine-tune confidence levels and attribution percentages:
834
+
835
+ ```yaml
836
+ attribution_rules:
837
+ vpc_specific_services:
838
+ confidence_level: "HIGH (98%)" # Custom confidence
839
+ attribution_percentage: 95 # Conservative 95%
840
+ service_patterns:
841
+ - "Amazon Virtual Private Cloud"
842
+ - "Amazon VPC"
843
+ - "AWS PrivateLink"
844
+ - "VPC Endpoint" # Add custom patterns
845
+ ```
846
+
847
+ #### Custom Output Columns
848
+
849
+ Customize CSV output columns:
850
+
851
+ ```yaml
852
+ output_config:
853
+ csv_columns:
854
+ - "VPC_ID"
855
+ - "Account_ID"
856
+ - "Region" # Add region
857
+ - "Deletion_Principal" # Add who deleted
858
+ - "Monthly_Savings_Realized"
859
+ - "Annual_Savings_Realized"
860
+ - "Confidence_Level"
861
+ - "Service_Analysis" # Add detailed breakdown
862
+ ```
863
+
864
+ ---
865
+
249
866
  **Optimization Recommendations**:
250
867
  ```
251
868
  ╭─ VPC Optimization Recommendations ─╮
runbooks/vpc/__init__.py CHANGED
@@ -23,8 +23,14 @@ from .manager_interface import BusinessRecommendation, ManagerDashboardConfig, V
23
23
  from .networking_wrapper import VPCNetworkingWrapper
24
24
  from .rich_formatters import display_cost_table, display_heatmap, display_optimization_recommendations
25
25
  from .vpc_cleanup_integration import VPCCleanupFramework, VPCCleanupCandidate, VPCCleanupRisk, VPCCleanupPhase
26
- from .cleanup_wrapper import VPCCleanupCLI, analyze_cleanup_candidates, validate_cleanup_safety, generate_business_report
26
+ from .cleanup_wrapper import (
27
+ VPCCleanupCLI,
28
+ analyze_cleanup_candidates,
29
+ validate_cleanup_safety,
30
+ generate_business_report,
31
+ )
27
32
  from .runbooks_adapter import RunbooksAdapter
33
+ from .nat_gateway_optimizer import NATGatewayOptimizer
28
34
 
29
35
  __all__ = [
30
36
  "VPCNetworkingWrapper",
@@ -45,6 +51,7 @@ __all__ = [
45
51
  "validate_cleanup_safety",
46
52
  "generate_business_report",
47
53
  "RunbooksAdapter",
54
+ "NATGatewayOptimizer",
48
55
  ]
49
56
 
50
57
  # Import centralized version from main runbooks package