This change request introduces significant improvements to the script used for listing and saving AWS SecurityHub automation rules across regions. The modified script not only lists the rules but also provides an option to save these rules as JSON files. Additionally, it includes error handling improvements and utilizes a custom Boto3 configuration for adaptive retry strategies.
Changes
Custom Boto3 Config: Introduced a custom configuration for Boto3 with an adaptive retry strategy to handle API rate limits and network issues more effectively.
Extended Argument Parsing: Added a new command-line argument --save-rules-json to enable the saving of rules as JSON files.
Rule Saving Functionality: Implemented a new function save_rule_to_json that takes a rule name, its data, and region to save the rule as a JSON file in the current directory.
Enhanced Rule Retrieval Logic: Modified the loop for listing automation rules to handle pagination correctly, ensuring all rules are retrieved even when they exceed the single request limit.
Full Rule Definitions Retrieval: Added functionality to fetch full definitions of each automation rule using the batch_get_automation_rules method and the list of rule ARNs.
Rule Definition Saving: Integrated the rule saving functionality within the main loop, allowing for each rule's full definition to be saved if the --save-rules-json flag is set.
Improved Error Handling: Enhanced error handling with more descriptive messages, especially for regional processing errors.
Benefits
Enhanced Functionality: Users can now not only list but also save the rule definitions, aiding in configuration management and documentation.
Improved Robustness: Custom Boto3 configuration and better error handling make the script more reliable in various network and API conditions.
Efficient Data Retrieval: Pagination handling ensures comprehensive data retrieval without missing any rules due to API response limits.
This change request introduces significant improvements to the script used for listing and saving AWS SecurityHub automation rules across regions. The modified script not only lists the rules but also provides an option to save these rules as JSON files. Additionally, it includes error handling improvements and utilizes a custom Boto3 configuration for adaptive retry strategies.
Changes
--save-rules-json
to enable the saving of rules as JSON files.save_rule_to_json
that takes a rule name, its data, and region to save the rule as a JSON file in the current directory.batch_get_automation_rules
method and the list of rule ARNs.--save-rules-json
flag is set.Benefits