runbooks 0.2.5__py3-none-any.whl → 0.7.0__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 (249) hide show
  1. conftest.py +26 -0
  2. jupyter-agent/.env +2 -0
  3. jupyter-agent/.env.template +2 -0
  4. jupyter-agent/.gitattributes +35 -0
  5. jupyter-agent/.gradio/certificate.pem +31 -0
  6. jupyter-agent/README.md +16 -0
  7. jupyter-agent/__main__.log +8 -0
  8. jupyter-agent/app.py +256 -0
  9. jupyter-agent/cloudops-agent.png +0 -0
  10. jupyter-agent/ds-system-prompt.txt +154 -0
  11. jupyter-agent/jupyter-agent.png +0 -0
  12. jupyter-agent/llama3_template.jinja +123 -0
  13. jupyter-agent/requirements.txt +9 -0
  14. jupyter-agent/tmp/4ojbs8a02ir/jupyter-agent.ipynb +68 -0
  15. jupyter-agent/tmp/cm5iasgpm3p/jupyter-agent.ipynb +91 -0
  16. jupyter-agent/tmp/crqbsseag5/jupyter-agent.ipynb +91 -0
  17. jupyter-agent/tmp/hohanq1u097/jupyter-agent.ipynb +57 -0
  18. jupyter-agent/tmp/jns1sam29wm/jupyter-agent.ipynb +53 -0
  19. jupyter-agent/tmp/jupyter-agent.ipynb +27 -0
  20. jupyter-agent/utils.py +409 -0
  21. runbooks/__init__.py +71 -3
  22. runbooks/__main__.py +13 -0
  23. runbooks/aws/ec2_describe_instances.py +1 -1
  24. runbooks/aws/ec2_run_instances.py +8 -2
  25. runbooks/aws/ec2_start_stop_instances.py +17 -4
  26. runbooks/aws/ec2_unused_volumes.py +5 -1
  27. runbooks/aws/s3_create_bucket.py +4 -2
  28. runbooks/aws/s3_list_objects.py +6 -1
  29. runbooks/aws/tagging_lambda_handler.py +13 -2
  30. runbooks/aws/tags.json +12 -0
  31. runbooks/base.py +353 -0
  32. runbooks/cfat/README.md +49 -0
  33. runbooks/cfat/__init__.py +74 -0
  34. runbooks/cfat/app.ts +644 -0
  35. runbooks/cfat/assessment/__init__.py +40 -0
  36. runbooks/cfat/assessment/asana-import.csv +39 -0
  37. runbooks/cfat/assessment/cfat-checks.csv +31 -0
  38. runbooks/cfat/assessment/cfat.txt +520 -0
  39. runbooks/cfat/assessment/collectors.py +200 -0
  40. runbooks/cfat/assessment/jira-import.csv +39 -0
  41. runbooks/cfat/assessment/runner.py +387 -0
  42. runbooks/cfat/assessment/validators.py +290 -0
  43. runbooks/cfat/cli.py +103 -0
  44. runbooks/cfat/docs/asana-import.csv +24 -0
  45. runbooks/cfat/docs/cfat-checks.csv +31 -0
  46. runbooks/cfat/docs/cfat.txt +335 -0
  47. runbooks/cfat/docs/checks-output.png +0 -0
  48. runbooks/cfat/docs/cloudshell-console-run.png +0 -0
  49. runbooks/cfat/docs/cloudshell-download.png +0 -0
  50. runbooks/cfat/docs/cloudshell-output.png +0 -0
  51. runbooks/cfat/docs/downloadfile.png +0 -0
  52. runbooks/cfat/docs/jira-import.csv +24 -0
  53. runbooks/cfat/docs/open-cloudshell.png +0 -0
  54. runbooks/cfat/docs/report-header.png +0 -0
  55. runbooks/cfat/models.py +1026 -0
  56. runbooks/cfat/package-lock.json +5116 -0
  57. runbooks/cfat/package.json +38 -0
  58. runbooks/cfat/report.py +496 -0
  59. runbooks/cfat/reporting/__init__.py +46 -0
  60. runbooks/cfat/reporting/exporters.py +337 -0
  61. runbooks/cfat/reporting/formatters.py +496 -0
  62. runbooks/cfat/reporting/templates.py +135 -0
  63. runbooks/cfat/run-assessment.sh +23 -0
  64. runbooks/cfat/runner.py +69 -0
  65. runbooks/cfat/src/actions/check-cloudtrail-existence.ts +43 -0
  66. runbooks/cfat/src/actions/check-config-existence.ts +37 -0
  67. runbooks/cfat/src/actions/check-control-tower.ts +37 -0
  68. runbooks/cfat/src/actions/check-ec2-existence.ts +46 -0
  69. runbooks/cfat/src/actions/check-iam-users.ts +50 -0
  70. runbooks/cfat/src/actions/check-legacy-cur.ts +30 -0
  71. runbooks/cfat/src/actions/check-org-cloudformation.ts +30 -0
  72. runbooks/cfat/src/actions/check-vpc-existence.ts +43 -0
  73. runbooks/cfat/src/actions/create-asanaimport.ts +14 -0
  74. runbooks/cfat/src/actions/create-backlog.ts +372 -0
  75. runbooks/cfat/src/actions/create-jiraimport.ts +15 -0
  76. runbooks/cfat/src/actions/create-report.ts +616 -0
  77. runbooks/cfat/src/actions/define-account-type.ts +51 -0
  78. runbooks/cfat/src/actions/get-enabled-org-policy-types.ts +40 -0
  79. runbooks/cfat/src/actions/get-enabled-org-services.ts +26 -0
  80. runbooks/cfat/src/actions/get-idc-info.ts +34 -0
  81. runbooks/cfat/src/actions/get-org-da-accounts.ts +34 -0
  82. runbooks/cfat/src/actions/get-org-details.ts +35 -0
  83. runbooks/cfat/src/actions/get-org-member-accounts.ts +44 -0
  84. runbooks/cfat/src/actions/get-org-ous.ts +35 -0
  85. runbooks/cfat/src/actions/get-regions.ts +22 -0
  86. runbooks/cfat/src/actions/zip-assessment.ts +27 -0
  87. runbooks/cfat/src/types/index.d.ts +147 -0
  88. runbooks/cfat/tests/__init__.py +141 -0
  89. runbooks/cfat/tests/test_cli.py +340 -0
  90. runbooks/cfat/tests/test_integration.py +290 -0
  91. runbooks/cfat/tests/test_models.py +505 -0
  92. runbooks/cfat/tests/test_reporting.py +354 -0
  93. runbooks/cfat/tsconfig.json +16 -0
  94. runbooks/cfat/webpack.config.cjs +27 -0
  95. runbooks/config.py +260 -0
  96. runbooks/finops/README.md +337 -0
  97. runbooks/finops/__init__.py +86 -0
  98. runbooks/finops/aws_client.py +245 -0
  99. runbooks/finops/cli.py +151 -0
  100. runbooks/finops/cost_processor.py +410 -0
  101. runbooks/finops/dashboard_runner.py +448 -0
  102. runbooks/finops/helpers.py +355 -0
  103. runbooks/finops/main.py +14 -0
  104. runbooks/finops/profile_processor.py +174 -0
  105. runbooks/finops/types.py +66 -0
  106. runbooks/finops/visualisations.py +80 -0
  107. runbooks/inventory/.gitignore +354 -0
  108. runbooks/inventory/ArgumentsClass.py +261 -0
  109. runbooks/inventory/FAILED_SCRIPTS_TROUBLESHOOTING.md +619 -0
  110. runbooks/inventory/Inventory_Modules.py +6130 -0
  111. runbooks/inventory/LandingZone/delete_lz.py +1075 -0
  112. runbooks/inventory/PASSED_SCRIPTS_GUIDE.md +738 -0
  113. runbooks/inventory/README.md +1320 -0
  114. runbooks/inventory/__init__.py +62 -0
  115. runbooks/inventory/account_class.py +532 -0
  116. runbooks/inventory/all_my_instances_wrapper.py +123 -0
  117. runbooks/inventory/aws_decorators.py +201 -0
  118. runbooks/inventory/aws_organization.png +0 -0
  119. runbooks/inventory/cfn_move_stack_instances.py +1526 -0
  120. runbooks/inventory/check_cloudtrail_compliance.py +614 -0
  121. runbooks/inventory/check_controltower_readiness.py +1107 -0
  122. runbooks/inventory/check_landingzone_readiness.py +711 -0
  123. runbooks/inventory/cloudtrail.md +727 -0
  124. runbooks/inventory/collectors/__init__.py +20 -0
  125. runbooks/inventory/collectors/aws_compute.py +518 -0
  126. runbooks/inventory/collectors/aws_networking.py +275 -0
  127. runbooks/inventory/collectors/base.py +222 -0
  128. runbooks/inventory/core/__init__.py +19 -0
  129. runbooks/inventory/core/collector.py +303 -0
  130. runbooks/inventory/core/formatter.py +296 -0
  131. runbooks/inventory/delete_s3_buckets_objects.py +169 -0
  132. runbooks/inventory/discovery.md +81 -0
  133. runbooks/inventory/draw_org_structure.py +748 -0
  134. runbooks/inventory/ec2_vpc_utils.py +341 -0
  135. runbooks/inventory/find_cfn_drift_detection.py +272 -0
  136. runbooks/inventory/find_cfn_orphaned_stacks.py +719 -0
  137. runbooks/inventory/find_cfn_stackset_drift.py +733 -0
  138. runbooks/inventory/find_ec2_security_groups.py +669 -0
  139. runbooks/inventory/find_landingzone_versions.py +201 -0
  140. runbooks/inventory/find_vpc_flow_logs.py +1221 -0
  141. runbooks/inventory/inventory.sh +659 -0
  142. runbooks/inventory/list_cfn_stacks.py +558 -0
  143. runbooks/inventory/list_cfn_stackset_operation_results.py +252 -0
  144. runbooks/inventory/list_cfn_stackset_operations.py +734 -0
  145. runbooks/inventory/list_cfn_stacksets.py +453 -0
  146. runbooks/inventory/list_config_recorders_delivery_channels.py +681 -0
  147. runbooks/inventory/list_ds_directories.py +354 -0
  148. runbooks/inventory/list_ec2_availability_zones.py +286 -0
  149. runbooks/inventory/list_ec2_ebs_volumes.py +244 -0
  150. runbooks/inventory/list_ec2_instances.py +425 -0
  151. runbooks/inventory/list_ecs_clusters_and_tasks.py +562 -0
  152. runbooks/inventory/list_elbs_load_balancers.py +411 -0
  153. runbooks/inventory/list_enis_network_interfaces.py +526 -0
  154. runbooks/inventory/list_guardduty_detectors.py +568 -0
  155. runbooks/inventory/list_iam_policies.py +404 -0
  156. runbooks/inventory/list_iam_roles.py +518 -0
  157. runbooks/inventory/list_iam_saml_providers.py +359 -0
  158. runbooks/inventory/list_lambda_functions.py +882 -0
  159. runbooks/inventory/list_org_accounts.py +446 -0
  160. runbooks/inventory/list_org_accounts_users.py +354 -0
  161. runbooks/inventory/list_rds_db_instances.py +406 -0
  162. runbooks/inventory/list_route53_hosted_zones.py +318 -0
  163. runbooks/inventory/list_servicecatalog_provisioned_products.py +575 -0
  164. runbooks/inventory/list_sns_topics.py +360 -0
  165. runbooks/inventory/list_ssm_parameters.py +402 -0
  166. runbooks/inventory/list_vpc_subnets.py +433 -0
  167. runbooks/inventory/list_vpcs.py +422 -0
  168. runbooks/inventory/lockdown_cfn_stackset_role.py +224 -0
  169. runbooks/inventory/models/__init__.py +24 -0
  170. runbooks/inventory/models/account.py +192 -0
  171. runbooks/inventory/models/inventory.py +309 -0
  172. runbooks/inventory/models/resource.py +247 -0
  173. runbooks/inventory/recover_cfn_stack_ids.py +205 -0
  174. runbooks/inventory/requirements.txt +12 -0
  175. runbooks/inventory/run_on_multi_accounts.py +211 -0
  176. runbooks/inventory/tests/common_test_data.py +3661 -0
  177. runbooks/inventory/tests/common_test_functions.py +204 -0
  178. runbooks/inventory/tests/setup.py +24 -0
  179. runbooks/inventory/tests/src.py +18 -0
  180. runbooks/inventory/tests/test_cfn_describe_stacks.py +208 -0
  181. runbooks/inventory/tests/test_ec2_describe_instances.py +162 -0
  182. runbooks/inventory/tests/test_inventory_modules.py +55 -0
  183. runbooks/inventory/tests/test_lambda_list_functions.py +86 -0
  184. runbooks/inventory/tests/test_moto_integration_example.py +273 -0
  185. runbooks/inventory/tests/test_org_list_accounts.py +49 -0
  186. runbooks/inventory/update_aws_actions.py +173 -0
  187. runbooks/inventory/update_cfn_stacksets.py +1215 -0
  188. runbooks/inventory/update_cloudwatch_logs_retention_policy.py +294 -0
  189. runbooks/inventory/update_iam_roles_cross_accounts.py +478 -0
  190. runbooks/inventory/update_s3_public_access_block.py +539 -0
  191. runbooks/inventory/utils/__init__.py +23 -0
  192. runbooks/inventory/utils/aws_helpers.py +510 -0
  193. runbooks/inventory/utils/threading_utils.py +493 -0
  194. runbooks/inventory/utils/validation.py +682 -0
  195. runbooks/inventory/verify_ec2_security_groups.py +1430 -0
  196. runbooks/main.py +1004 -0
  197. runbooks/organizations/__init__.py +12 -0
  198. runbooks/organizations/manager.py +374 -0
  199. runbooks/security/README.md +447 -0
  200. runbooks/security/__init__.py +71 -0
  201. runbooks/{security_baseline → security}/checklist/alternate_contacts.py +8 -1
  202. runbooks/{security_baseline → security}/checklist/bucket_public_access.py +4 -1
  203. runbooks/{security_baseline → security}/checklist/cloudwatch_alarm_configuration.py +9 -2
  204. runbooks/{security_baseline → security}/checklist/guardduty_enabled.py +9 -2
  205. runbooks/{security_baseline → security}/checklist/multi_region_instance_usage.py +5 -1
  206. runbooks/{security_baseline → security}/checklist/root_access_key.py +6 -1
  207. runbooks/{security_baseline → security}/config-origin.json +1 -1
  208. runbooks/{security_baseline → security}/config.json +1 -1
  209. runbooks/{security_baseline → security}/permission.json +1 -1
  210. runbooks/{security_baseline → security}/report_generator.py +10 -2
  211. runbooks/{security_baseline → security}/report_template_en.html +7 -7
  212. runbooks/{security_baseline → security}/report_template_jp.html +7 -7
  213. runbooks/{security_baseline → security}/report_template_kr.html +12 -12
  214. runbooks/{security_baseline → security}/report_template_vn.html +7 -7
  215. runbooks/{security_baseline → security}/run_script.py +8 -2
  216. runbooks/{security_baseline → security}/security_baseline_tester.py +12 -4
  217. runbooks/{security_baseline → security}/utils/common.py +5 -1
  218. runbooks/utils/__init__.py +204 -0
  219. runbooks-0.7.0.dist-info/METADATA +375 -0
  220. runbooks-0.7.0.dist-info/RECORD +249 -0
  221. {runbooks-0.2.5.dist-info → runbooks-0.7.0.dist-info}/WHEEL +1 -1
  222. runbooks-0.7.0.dist-info/entry_points.txt +7 -0
  223. runbooks-0.7.0.dist-info/licenses/LICENSE +201 -0
  224. runbooks-0.7.0.dist-info/top_level.txt +3 -0
  225. runbooks/python101/calculator.py +0 -34
  226. runbooks/python101/config.py +0 -1
  227. runbooks/python101/exceptions.py +0 -16
  228. runbooks/python101/file_manager.py +0 -218
  229. runbooks/python101/toolkit.py +0 -153
  230. runbooks-0.2.5.dist-info/METADATA +0 -439
  231. runbooks-0.2.5.dist-info/RECORD +0 -61
  232. runbooks-0.2.5.dist-info/entry_points.txt +0 -3
  233. runbooks-0.2.5.dist-info/top_level.txt +0 -1
  234. /runbooks/{security_baseline/__init__.py → inventory/tests/script_test_data.py} +0 -0
  235. /runbooks/{security_baseline → security}/checklist/__init__.py +0 -0
  236. /runbooks/{security_baseline → security}/checklist/account_level_bucket_public_access.py +0 -0
  237. /runbooks/{security_baseline → security}/checklist/direct_attached_policy.py +0 -0
  238. /runbooks/{security_baseline → security}/checklist/iam_password_policy.py +0 -0
  239. /runbooks/{security_baseline → security}/checklist/iam_user_mfa.py +0 -0
  240. /runbooks/{security_baseline → security}/checklist/multi_region_trail.py +0 -0
  241. /runbooks/{security_baseline → security}/checklist/root_mfa.py +0 -0
  242. /runbooks/{security_baseline → security}/checklist/root_usage.py +0 -0
  243. /runbooks/{security_baseline → security}/checklist/trail_enabled.py +0 -0
  244. /runbooks/{security_baseline → security}/checklist/trusted_advisor.py +0 -0
  245. /runbooks/{security_baseline → security}/utils/__init__.py +0 -0
  246. /runbooks/{security_baseline → security}/utils/enums.py +0 -0
  247. /runbooks/{security_baseline → security}/utils/language.py +0 -0
  248. /runbooks/{security_baseline → security}/utils/level_const.py +0 -0
  249. /runbooks/{security_baseline → security}/utils/permission_list.py +0 -0
@@ -0,0 +1,201 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ AWS Landing Zone Version Discovery and Analysis Script
4
+
5
+ Comprehensive enterprise-grade tool for discovering, enumerating, and analyzing AWS Landing Zone
6
+ (ALZ) deployments across multiple AWS profiles and organizational environments. Designed for
7
+ enterprise infrastructure governance, compliance monitoring, and Landing Zone lifecycle management
8
+ with multi-profile authentication and automated version tracking capabilities.
9
+
10
+ Key Features:
11
+ - Multi-profile AWS Landing Zone discovery and version identification
12
+ - Automated Management Account detection through CloudFormation stack analysis
13
+ - Landing Zone solution version extraction from CloudFormation outputs
14
+ - Comprehensive tabular reporting with profile, account, region, and version details
15
+ - Enterprise authentication with multi-profile credential management
16
+ - Extensive error handling for credential and configuration issues
17
+
18
+ Enterprise Capabilities:
19
+ - Organizational Landing Zone inventory and lifecycle tracking
20
+ - Multi-environment Landing Zone version compliance monitoring
21
+ - Automated Management Account identification for governance operations
22
+ - Cross-profile Landing Zone deployment visibility and analysis
23
+ - Enterprise credential management with comprehensive error handling
24
+ - Scalable processing for large-scale multi-account environments
25
+
26
+ Operational Use Cases:
27
+ - Landing Zone version audit and compliance tracking across organizations
28
+ - Management Account discovery for organizational governance operations
29
+ - Infrastructure inventory for Landing Zone upgrade planning and coordination
30
+ - Enterprise compliance monitoring through systematic Landing Zone analysis
31
+ - Multi-environment Landing Zone deployment tracking and management
32
+
33
+ Output Format:
34
+ - Tabular display with Profile, Account, Region, Stack Name, and Version information
35
+ - Comprehensive operational metrics including profile count and Landing Zone discovery statistics
36
+ - Color-coded terminal output for enhanced operational visibility
37
+ - Structured data presentation for integration with enterprise reporting systems
38
+
39
+ Authentication & Security:
40
+ - Multi-profile AWS credential management with comprehensive validation
41
+ - Cross-account access through profile-based authentication
42
+ - Extensive error handling for credential retrieval and configuration issues
43
+ - Regional validation and access control for secure Landing Zone operations
44
+
45
+ Performance & Scale:
46
+ - Efficient multi-profile processing for large-scale organizational environments
47
+ - Memory-efficient CloudFormation stack analysis and version extraction
48
+ - Progress indicators for enhanced user experience during discovery operations
49
+ - Optimized API usage patterns for improved performance and reduced throttling
50
+
51
+ Landing Zone Detection Logic:
52
+ - CloudFormation stack analysis for Landing Zone identification (SO0044 solution)
53
+ - Stack description parsing for AWS Landing Zone solution identification
54
+ - Output key extraction for precise Landing Zone version determination
55
+ - Multi-stack analysis ensuring comprehensive Landing Zone discovery
56
+
57
+ Error Handling & Resilience:
58
+ - Comprehensive credential error handling with specific error type identification
59
+ - AWS API authorization failure detection with detailed troubleshooting guidance
60
+ - Configuration validation with profile-specific error messaging
61
+ - Graceful degradation for inaccessible profiles maintaining operation continuity
62
+
63
+ Dependencies:
64
+ - boto3: AWS SDK for CloudFormation and credential management
65
+ - Custom modules: Inventory_Modules, ArgumentsClass
66
+ - colorama: Enhanced terminal output and progress indicators
67
+
68
+ Authors: AWS CloudOps Team
69
+ Version: 2023.05.31
70
+ License: MIT
71
+ """
72
+
73
+ import logging
74
+
75
+ import boto3
76
+ import Inventory_Modules
77
+ from ArgumentsClass import CommonArguments
78
+ from botocore.exceptions import ClientError, CredentialRetrievalError, InvalidConfigError
79
+ from colorama import init
80
+
81
+ # Initialize colorama for cross-platform colored terminal output
82
+ init()
83
+
84
+ __version__ = "2023.05.31"
85
+
86
+ # Configure comprehensive CLI argument parsing for Landing Zone discovery operations
87
+ parser = CommonArguments()
88
+ parser.multiprofile() # Multi-profile authentication for organizational Landing Zone discovery
89
+ parser.verbosity() # Configurable logging levels for operational visibility
90
+ parser.version(__version__) # Script version tracking for compatibility management
91
+ args = parser.my_parser.parse_args()
92
+
93
+ # Extract CLI arguments for Landing Zone discovery and operational configuration
94
+ pProfiles = args.Profiles # AWS profiles for multi-account Landing Zone analysis
95
+ verbose = args.loglevel # Logging verbosity for operational monitoring and troubleshooting
96
+
97
+ # Configure comprehensive logging for Landing Zone discovery operations
98
+ logging.basicConfig(
99
+ level=args.loglevel, format="[%(filename)s:%(lineno)s:%(levelname)s - %(funcName)30s() ] %(message)s"
100
+ )
101
+
102
+ ##########################
103
+ # Terminal control and operational configuration constants
104
+ ERASE_LINE = "\x1b[2K" # ANSI escape sequence for clearing terminal line during progress display
105
+ SkipProfiles = ["default"] # Profile exclusion list for organizational Landing Zone discovery
106
+
107
+ # Configure AWS profile discovery strategy based on user input
108
+ if pProfiles is None:
109
+ # Default to single profile when no specific profiles are specified
110
+ print(f"You've provided no profile, so we'll use the default")
111
+ AllProfiles = ["default"]
112
+ elif "all" in pProfiles or "ALL" in pProfiles or "All" in pProfiles:
113
+ # Comprehensive multi-profile Landing Zone discovery across all available profiles
114
+ logging.info(
115
+ f"You specified 'all' as the profile, so we're going to check ALL of the profiles to find all of the management accounts, and list out all of their ALZ versions."
116
+ )
117
+ print(
118
+ "You've specified multiple profiles, so we've got to find them, determine which profiles represent Management Accounts, \n"
119
+ "and then parse through those. This will take a few moments."
120
+ )
121
+ # Discover all available profiles excluding specified skip profiles
122
+ AllProfiles = Inventory_Modules.get_profiles(fSkipProfiles=SkipProfiles, fprofiles=pProfiles)
123
+ else:
124
+ # Targeted profile-specific Landing Zone discovery based on user selection
125
+ AllProfiles = Inventory_Modules.get_profiles(fSkipProfiles=SkipProfiles, fprofiles=pProfiles)
126
+
127
+ # Execute comprehensive Landing Zone discovery across all configured profiles
128
+ ALZProfiles = [] # Initialize Landing Zone profile collection for discovered Management Accounts
129
+
130
+ for profile in AllProfiles:
131
+ # Display real-time progress during profile analysis with terminal line clearing
132
+ print(f"{ERASE_LINE}Checking profile: {profile}", end="\r")
133
+
134
+ try:
135
+ # Analyze current profile to determine if it represents an AWS Landing Zone Management Account
136
+ ALZMgmntAcct = Inventory_Modules.find_if_alz(profile)
137
+
138
+ if ALZMgmntAcct["ALZ"]:
139
+ # Extract account metadata for confirmed Landing Zone Management Accounts
140
+ accountnum = Inventory_Modules.find_account_number(profile)
141
+ ALZProfiles.append({"Profile": profile, "Acctnum": accountnum, "Region": ALZMgmntAcct["Region"]})
142
+
143
+ except ClientError as my_Error:
144
+ # Handle AWS API client errors with specific error type identification
145
+ if str(my_Error).find("UnrecognizedClientException") > 0:
146
+ logging.error("%s: Security Issue", profile)
147
+ elif str(my_Error).find("InvalidClientTokenId") > 0:
148
+ logging.error("%s: Security Token is bad - probably a bad entry in config", profile)
149
+ pass
150
+
151
+ except CredentialRetrievalError as my_Error:
152
+ # Handle credential retrieval errors for custom authentication processes
153
+ if str(my_Error).find("CredentialRetrievalError") > 0:
154
+ logging.error("%s: Some custom process isn't working", profile)
155
+ pass
156
+
157
+ except InvalidConfigError as my_Error:
158
+ # Handle configuration validation errors for profile-specific credential issues
159
+ if str(my_Error).find("InvalidConfigError") > 0:
160
+ logging.error(
161
+ "%s: profile is invalid. Probably due to a config profile based on a credential that doesn't work",
162
+ profile,
163
+ )
164
+ pass
165
+
166
+ # Clear progress display and initialize tabular output formatting for Landing Zone inventory
167
+ print(ERASE_LINE)
168
+ fmt = "%-20s %-13s %-15s %-35s %-21s" # Column formatting for structured Landing Zone data display
169
+ print(fmt % ("Profile", "Account", "Region", "ALZ Stack Name", "ALZ Version"))
170
+ print(fmt % ("-------", "-------", "------", "--------------", "-----------"))
171
+
172
+ # Execute comprehensive Landing Zone version analysis for each discovered Management Account
173
+ for item in ALZProfiles:
174
+ # Establish authenticated AWS session for CloudFormation stack analysis
175
+ aws_session = boto3.Session(profile_name=item["Profile"], region_name=item["Region"])
176
+ aws_client = aws_session.client("cloudformation")
177
+
178
+ # Retrieve comprehensive CloudFormation stack inventory for Landing Zone identification
179
+ stack_list = aws_client.describe_stacks()["Stacks"]
180
+
181
+ # Analyze each CloudFormation stack for AWS Landing Zone solution identification
182
+ for i in range(len(stack_list)):
183
+ logging.warning(f"Checking stack {stack_list[i]['StackName']} to see if it is the ALZ initiation stack")
184
+
185
+ # Identify Landing Zone stacks through solution ID (SO0044) in stack description
186
+ if "Description" in stack_list[i].keys() and stack_list[i]["Description"].find("SO0044") > 0:
187
+ # Extract Landing Zone version from CloudFormation stack outputs
188
+ for j in range(len(stack_list[i]["Outputs"])):
189
+ if stack_list[i]["Outputs"][j]["OutputKey"] == "LandingZoneSolutionVersion":
190
+ # Extract and display Landing Zone version information with formatted output
191
+ ALZVersion = stack_list[i]["Outputs"][j]["OutputValue"]
192
+ print(
193
+ fmt % (item["Profile"], item["Acctnum"], item["Region"], stack_list[i]["StackName"], ALZVersion)
194
+ )
195
+
196
+ # Display comprehensive operational summary with discovery metrics
197
+ print(ERASE_LINE)
198
+ print(f"Checked {len(AllProfiles)} accounts/ Orgs. Found {len(ALZProfiles)} ALZs")
199
+ print()
200
+ print("Thank you for using this script.")
201
+ print()