API Reference¶
This section contains the complete API documentation auto-generated from source code docstrings.
Core Modules¶
S3 Manager¶
- class s3_provisioner.core.s3_manager.S3Manager(config_file_name, action, solution=None, dry_run=False, log_level='INFO', force=False, app_config=None)¶
Bases:
objectManages S3 bucket provisioning and ML solution folder structures for AWS.
This class provides comprehensive S3 infrastructure management for ML workloads, including CloudFormation-based bucket creation, folder structure generation, lifecycle policies, VPC endpoints, and Parameter Store integration.
The S3Manager supports multiple ML solutions with standardized folder hierarchies for data, models, notebooks, artifacts, code, and configuration files. It uses .gitkeep files to maintain folder visibility in S3 and provides flexible visibility control through depth-based filtering.
- Key Features:
CloudFormation template generation for S3 infrastructure
Automated ML folder structure creation (70+ folders per solution)
VPC endpoint configuration for private S3 access
Lifecycle policy management (ml-optimized, compliance, development)
IAM policy generation for least-privilege access
Parameter Store integration for infrastructure outputs
Dry-run mode for safe testing
Force deletion with automatic cleanup
- s3_client¶
Boto3 S3 client
- cf_client¶
Boto3 CloudFormation client
- ssm_client¶
Boto3 Systems Manager client
- logger¶
Configured logger instance
- Class Constants:
DEFAULT_LAMBDA_RUNTIME (str): Lambda runtime version for custom resources DEFAULT_LAMBDA_TIMEOUT (int): Lambda timeout in seconds STACK_CREATE_WAITER_DELAY (int): Delay between stack creation checks (seconds) STACK_CREATE_WAITER_MAX_ATTEMPTS (int): Maximum stack creation wait attempts STACK_DELETE_WAITER_DELAY (int): Delay between stack deletion checks (seconds) STACK_DELETE_WAITER_MAX_ATTEMPTS (int): Maximum stack deletion wait attempts S3_DELETE_BATCH_SIZE (int): Maximum objects to delete in single batch GITKEEP_PARTIAL_DEPTH (int): Folder depth for partial visibility control DEFAULT_REGION (str): Default AWS region if not specified
Example
>>> from s3_provisioner.core import S3Manager >>> manager = S3Manager( ... config_file_name='config.yaml', ... action='create-bucket', ... solution='customer-churn', ... dry_run=False ... ) >>> exit_code = manager.execute()
Note
Requires valid AWS credentials with appropriate IAM permissions
Configuration file must pass JSON schema validation
Some actions require –solution parameter
Use dry_run=True to preview changes before execution
- DEFAULT_LAMBDA_RUNTIME = 'python3.12'¶
- DEFAULT_LAMBDA_TIMEOUT = 120¶
- STACK_CREATE_WAITER_DELAY = 10¶
- STACK_CREATE_WAITER_MAX_ATTEMPTS = 60¶
- STACK_DELETE_WAITER_DELAY = 10¶
- STACK_DELETE_WAITER_MAX_ATTEMPTS = 60¶
- S3_DELETE_BATCH_SIZE = 1000¶
- GITKEEP_PARTIAL_DEPTH = 5¶
- DEFAULT_REGION = 'us-east-1'¶
- DRIFT_POLL_INTERVAL = 10¶
- DRIFT_POLL_TIMEOUT = 600¶
- CHANGESET_POLL_INTERVAL = 5¶
- CHANGESET_MAX_ATTEMPTS = 60¶
- __init__(config_file_name, action, solution=None, dry_run=False, log_level='INFO', force=False, app_config=None)¶
Inintialize class members from config file and parameters.
- Parameters:
config_file_name (
str) – Name of the configuration file.action (
str) – Action to be performed.solution (
Optional[str]) – Name of the business solution (optional for some actions).dry_run (
bool) – Dry run flag, if True no changes are made.log_level (
str) – Logging level for the operation.force (
bool) – Force flag, if True certain validations are skipped.app_config (AppConfig) – Application configuration object (AppConfig instance).
- execute()¶
Executes the specified action on the S3 folder. This method serves as the main entry point for executing the desired action based on the command provided. It first displays the class members for debugging purposes, then validates any requirements for the specified action (e.g., checking if the –solution parameter is provided for actions that require it). Finally, it calls the _execute_action method to perform the actual execution of the action and returns 0 for success or 1 for failure based on the result.
- Returns:
0 for success, 1 for failure.
- Return type:
Configuration¶
Configuration Loader¶
- class s3_provisioner.config.loader.AppConfig(config_dict)¶
Bases:
objectApplication configuration with embedded defaults.
Loads configuration from YAML files and provides convenient access to configuration values with automatic path resolution.
- Features:
Loads config from provided dictionary (from YAML)
Resolves directory paths to absolute paths
Provides access to config values via get() method with dot notation
Handles directory path resolution and validation
- __init__(config_dict)¶
Initializes the config object with config dictionary.
- get(key_path, default=None)¶
Gets a config value using dot notation.
- get_directory(dir_name)¶
Gets a directory path as a Path object.
- Parameters:
dir_name (
str) – Directory name (configs_dir, reports_dir, etc.)- Returns:
Path object
- Return type:
- Raises:
ValueError – If directory not configured
- s3_provisioner.config.loader.load_app_config(custom_config_path=None)¶
Loads and returns application configuration.
Resolution order: 1. Custom config file (if provided via –app-config) 2. Embedded default config (always available)
- Parameters:
custom_config_path (
Optional[str]) – Optional path to custom config file- Returns:
AppConfig instance
- Return type:
- Raises:
FileNotFoundError – If custom config specified but not found
ValueError – If config file is invalid YAML
Utilities¶
HTML Generator¶
HTML documentation generator for S3 provisioning.
Provides two report types:
generate_template_documentation()— CloudFormation template overviewgenerate_deployment_documentation()— post-deployment stack report
- s3_provisioner.utils.html_generator.generate_template_documentation(config_file, template_file, cfn_template, solution, output_path)¶
Generate HTML documentation for CloudFormation template.
- Parameters:
- Returns:
Path to generated HTML file.
- Return type:
- s3_provisioner.utils.html_generator.generate_deployment_documentation(config_file, stack_name, region, stack_info, solution, output_path)¶
Generate HTML documentation for S3 deployment.
- Parameters:
- Returns:
Path to generated HTML file.
- Return type:
- s3_provisioner.utils.html_generator.generate_cost_report(bucket_name, region, config_file, cost_result, pricing_source, output_path)¶
Generate HTML cost estimation report for S3 infrastructure.
Produces a professional HTML document with a cost breakdown table showing storage, request, data transfer, and VPC Endpoint costs with monthly and annual totals.
- Parameters:
bucket_name (
str) – Name of the S3 bucket.region (
str) – AWS region code.config_file (
str) – Path to the S3 configuration YAML file.cost_result (
Dict[str,Any]) – Cost breakdown dictionary fromcalculate().pricing_source (
str) – Description of the pricing source.output_path (
str) – Filesystem path where the HTML file should be saved.
- Returns:
Path to the generated HTML file.
- Return type:
- Raises:
PermissionError – If the output path is not writable.
OSError – If file writing fails.
License¶
License Validator¶
- class s3_provisioner.license.validator.LicenseValidator¶
Bases:
objectValidates product licenses against the AWS Marketplace License Manager.
This class handles the end-to-end license verification workflow, including secure communication with AWS APIs to confirm customer entitlements. To optimize performance and minimize latency, it employs an in-memory caching mechanism, reducing API calls for frequently validated tokens or customers.
- license_client¶
Boto3 client for AWS Marketplace License Manager.
- key_fingerprint¶
The fingerprint of the public key used for license validation.
- entitlement_name¶
The name of the entitlement to check for in the AWS License Manager.
- cache_duration¶
Duration for which the cache is considered valid (hours).
- Type:
timedelta
- Integration Workflow:
Checks cache for active, unexpired validation result.
If missing/expired, calls CheckoutLicense API.
Validates product SKU and entitlement status.
Updates cache and returns validation status.
- __init__()¶
Initialize the LicenseValidator with AWS Marketplace configuration.
Reads configuration from environment variables and sets up the AWS License Manager client for license validation.
- Environment Variables:
MARKETPLACE_PRODUCT_SKU: AWS Marketplace product SKU (required for validation) AWS_REGION: AWS region for Marketplace API (default: ‘us-east-1’)
CLI Interface¶
- class s3_provisioner.cli.S3ProvisionerCLI¶
Bases:
BaseCLICLI for S3 Provisioner Tool.
Extends
BaseCLIto implement S3-specific actions and arguments. Supports 16 actions grouped by safety level:Local: validate-config, create-prov-template, validate-prov-template, create-policy
Bucket operations: create-bucket, deploy-solution, deploy-folders, upload-template, prep-master
Gitkeep management: gitkeep-full, gitkeep-none, gitkeep-partial
Read-only: show-changes, check-drift
Testing: test-deploy
Destructive: purge-bucket, delete-bucket, delete-cfn-stack, tear-down
Includes AWS Marketplace license validation before executing any actions.
- __init__()¶
Initialize the S3 Provisioner CLI.
- is_action_required()¶
Determine if an action argument is required for this CLI.
- Return type:
- Returns:
Always True for this CLI
- get_actions()¶
Return the list of valid actions for the S3 Provisioner CLI.
- get_actions_help()¶
Return help text describing all available actions.
- Return type:
- Returns:
Formatted help text for all S3 actions
- get_manager_class()¶
Return the manager class for this CLI.
- get_example_usage()¶
Return example usage instructions.
Detects Docker environment via
/.dockerenvor/proc/1/cgroupand adjusts command examples accordingly.- Returns:
Example usage string with Docker or native CLI commands.
- Return type:
- add_custom_arguments(parser)¶
Add S3 Provisioner-specific CLI arguments.
- create_manager_instance(args)¶
Create a new
S3Managerinstance.- Parameters:
args (argparse.Namespace) – Parsed command-line arguments.
- Returns:
Instance initialized with CLI arguments and app config.
- Return type:
- s3_provisioner.cli.main()¶
Entry point for S3 Provisioner CLI.
Validates AWS Marketplace license before running the CLI. Exits with code 1 if license validation fails.