API Reference¶
This section contains the complete API documentation auto-generated from source code docstrings.
Core Modules¶
ML Manager¶
- class ml_provisioner.core.ml_manager.MlManager(config_file_name, action, dry_run=False, log_level='INFO', force=False, app_config=None)¶
Bases:
objectManages AWS ML project infrastructure provisioning and lifecycle operations using CloudFormation.
This class provides tier-based ML project scaffolding for enterprise workloads. It loads pre-built tier blueprints (starter, professional, enterprise), applies client configuration, validates security rules, generates CloudFormation templates, and manages the complete ML product lifecycle from creation to deletion.
- Key Features:
Tier-based ML project generation (starter, professional, enterprise)
Generic use-case parameterization — use_case drives resource naming only
Pure data definition blueprints — no placeholder substitution
CloudFormation template generation via programmatic Python dict construction
Parameter Store integration for ML resource ID storage
IAM policy generation for least-privilege access
Conditional generation for source_control (codecommit/s3) and vpc_integration mode
Dry-run mode for safe testing
Force flag for mutating operations
- cf_client¶
Boto3 CloudFormation client
- ssm_client¶
Boto3 Systems Manager client
- logger¶
Configured logger instance
- Class Constants:
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 DRIFT_POLL_INTERVAL (int): Seconds between drift status checks DRIFT_POLL_TIMEOUT (int): Total timeout for drift detection (10 minutes) CHANGESET_POLL_INTERVAL (int): Seconds between changeset status checks CHANGESET_MAX_ATTEMPTS (int): Maximum attempts for changeset creation
Example
>>> from ml_provisioner.core import MlManager >>> manager = MlManager( ... config_file_name='globalbank-prod-c001-us-west-1-demand-forecasting-ml.yaml', ... action='create-prov-template', ... dry_run=False ... ) >>> exit_code = manager.execute()
Note
Requires valid AWS credentials with appropriate IAM permissions
Configuration file must pass validation schema
Use dry_run=True to preview changes before execution
Enterprise tier requires VPC to be deployed before deployment
- CHANGESET_MAX_ATTEMPTS = 60¶
- CHANGESET_POLL_INTERVAL = 5¶
- DRIFT_POLL_INTERVAL = 10¶
- DRIFT_POLL_TIMEOUT = 600¶
- STACK_CREATE_WAITER_DELAY = 10¶
- STACK_CREATE_WAITER_MAX_ATTEMPTS = 60¶
- STACK_DELETE_WAITER_DELAY = 10¶
- STACK_DELETE_WAITER_MAX_ATTEMPTS = 60¶
- __init__(config_file_name, action, dry_run=False, log_level='INFO', force=False, app_config=None)¶
Initializes class members from config file and parameters.
- Parameters:
config_file_name (str) – Name of the configuration file.
action (str) – Action to be performed.
dry_run (bool) – Dry run flag, if True no changes are made.
log_level (str) – Logging level for the operation.
force (bool) – If True, forces mutating AWS operations without confirmation.
app_config (AppConfig) – Application configuration object (AppConfig instance).
Configuration¶
Configuration Loader¶
- class ml_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.
- Parameters:
config_dict (Dict[str, Any])
- 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.)
- Raises:
ValueError – If directory not configured
- Return type:
- ml_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)
- Raises:
FileNotFoundError – If custom config specified but not found
ValueError – If config file is invalid YAML
- Parameters:
custom_config_path (str | None)
- Return type:
Generators¶
CloudFormation Generator¶
- class ml_provisioner.generators.cfn_generator.CfnGenerator(blueprint, config, ml_name_override=None)¶
Bases:
objectGenerates CloudFormation templates from a product blueprint and client configuration.
Resolves all config values at construction time and exposes a single generate() method that returns a complete CFN template dict.
- __init__(blueprint, config, ml_name_override=None)¶
Utilities¶
HTML Generator¶
HTML documentation generator for ML provisioning.
Provides post-deployment reporting:
generate_deployment_documentation()— CONFIDENTIAL stack report with live resource IDs
- ml_provisioner.utils.html_generator.generate_deployment_documentation(config_file, stack_name, region, stack_info, output_path)¶
Generate CONFIDENTIAL HTML report for ML product deployment with live resource IDs.
- Parameters:
- Returns:
Path to generated HTML file.
- Return type:
Review Report¶
Pre-deployment review report generator for ML provisioning.
Produces an HTML report summarizing what will be deployed:
generate_review_html()— human-friendly HTML with config summary, resources grouped by category, and SSM paths to be published.
- ml_provisioner.utils.review_report.generate_review_html(blueprint, config_data, ml_name, output_path)¶
Generate an HTML pre-deployment review report for an ML product.
- Parameters:
- Returns:
Path to the generated HTML file.
- Return type:
Products¶
Product Loader¶
- class ml_provisioner.products.loader.ProductLoader¶
Bases:
objectLoads tier blueprint definitions from YAML files in schemas/products/.
The loader reads pure data definition YAML files (starter.yaml, professional.yaml, enterprise.yaml) and maps them into ProductBlueprint dataclasses. No placeholder substitution or override merging is performed here — that is the responsibility of CfnGenerator.
The YAML files are self-contained — each tier file includes all resources from previous tiers plus its own additions. The loader reads the file as-is without any inheritance or merging logic.
- VALID_TIERS = {'enterprise', 'professional', 'starter'}¶
- list_products(products_dir)¶
Scans the products directory and returns metadata for all available tiers.
- Parameters:
products_dir (Path) – Path to the schemas/products/ directory.
- Returns:
- List of dicts with ‘tier’, ‘version’,
’description’, and ‘resource_count’ keys, sorted by tier order (starter → professional → enterprise).
- Return type:
List[Dict[str, Any]]
- Raises:
FileNotFoundError – If the products directory does not exist.
- load_product(tier, products_dir)¶
Loads a tier blueprint YAML file and maps it into a ProductBlueprint dataclass.
- Parameters:
tier (str) – Tier name — starter, professional, or enterprise.
products_dir (Path) – Path to the schemas/products/ directory.
- Returns:
Fully constructed ProductBlueprint object.
- Return type:
ProductBlueprint
- Raises:
ValueError – If tier is not one of starter, professional, enterprise.
FileNotFoundError – If the tier YAML file does not exist.
ValueError – If the YAML file is empty or malformed.
Product Validator¶
- class ml_provisioner.products.validator.ProductValidator¶
Bases:
objectValidates a ProductBlueprint against security and structural rules before CloudFormation template generation.
Checks are scoped strictly to resources provisioned by ML Provisioner. Issues are categorized as ERROR (blocks generation) or WARNING (proceeds with warning). See APPLICATION_ARCHITECTURE.md Security Validation section for the full rationale behind each check.
- Class Constants:
WARNING (str): Warning level — generation proceeds with warning. ERROR (str): Error level — generation halted unless –force is used. SENSITIVE_IAM_ACTIONS (set): High-risk IAM actions that trigger a warning. HARDCODED_KEY_PATTERN (re.Pattern): Regex to detect plaintext AWS access keys. MIN_LOG_RETENTION_DAYS (int): Minimum CloudWatch log retention in days. BLOCKED_PORTS (set): Ports blocked from 0.0.0.0/0 on endpoint SecurityGroup.
- ERROR = 'ERROR'¶
- HARDCODED_KEY_PATTERN = re.compile('(?:AKIA|ASIA)[0-9A-Z]{16}')¶
- MIN_LOG_RETENTION_DAYS = 90¶
- WARNING = 'WARNING'¶
- validate(blueprint, config_data)¶
Run all validation checks on the blueprint and client config.
- Parameters:
blueprint (ProductBlueprint) – Loaded tier blueprint to validate.
config_data (dict) – Raw client configuration dictionary.
- Returns:
List of issues found. Empty list means clean.
- Return type:
List[ValidationIssue]
Data Models¶
Product Blueprint¶
- class ml_provisioner.models.product.ProductBlueprint(tier, version, description, resources=<factory>, ssm_outputs=<factory>)
Bases:
objectRepresents a complete tier blueprint loaded from a schemas/products YAML file.
A ProductBlueprint is a pure data definition — it declares what resources exist and their structure. It contains no CloudFormation syntax, no client-specific values, and no placeholder tokens. The CfnGenerator reads this alongside the client config to construct the final CloudFormation template.
- Parameters:
- tier
Tier identifier — starter, professional, or enterprise.
- Type:
- version
Blueprint version string.
- Type:
- description
Human-readable description of the tier.
- Type:
- resources
Ordered list of resource definitions.
- Type:
List[ResourceDefinition]
- ssm_outputs
List of SSM Parameter Store output keys to store after deployment (e.g., ‘ModelPackageGroupArn’, ‘RepositoryUrl’).
- Type:
List[str]
- __init__(tier, version, description, resources=<factory>, ssm_outputs=<factory>)
- get_resource_by_key(key)
Lookup a resource definition by its logical key.
- Parameters:
key (str) – The logical key of the resource to find.
- Returns:
The matching resource, or None if not found.
- Return type:
Optional[ResourceDefinition]
- get_resources_by_type(resource_type)
Return all resource definitions matching a given CloudFormation type.
- Parameters:
resource_type (str) – CloudFormation resource type to filter by (e.g., ‘AWS::IAM::Role’).
- Returns:
List of matching resource definitions.
- Return type:
List[ResourceDefinition]
- tier: str
- version: str
- description: str
- resources: List[ResourceDefinition]
- class ml_provisioner.models.product.ResourceDefinition(key, type, properties=<factory>)
Bases:
objectRepresents a single resource entry in a tier blueprint.
- key
Logical key identifying the resource (e.g., ‘sagemaker_project’).
- Type:
- type
AWS CloudFormation resource type (e.g., ‘AWS::SageMaker::Project’).
- Type:
- properties
Additional properties from the blueprint (e.g., count, names, versioning, condition, services, encrypt).
- Type:
Dict[str, Any]
- __init__(key, type, properties=<factory>)
- key: str
- type: str
License¶
License Validator¶
- class ml_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 ml_provisioner.cli.MlProvisionerCLI¶
Bases:
BaseCLICLI for ML Provisioner Tool.
Extends
BaseCLIto implement ML-specific actions and arguments. Supports 12 actions grouped by safety level:- Local: validate-config, list-products, show-product, create-policy,
create-prov-template, validate-prov-template, create-review-report
Read-only: show-changes, check-drift
Mutating: test-deploy, deploy-product, delete-product
Includes AWS Marketplace license validation before executing any actions.
- __init__()¶
Initialize the ML Provisioner CLI.
- add_custom_arguments(parser)¶
Add ML Provisioner-specific CLI arguments.
- Parameters:
parser (argparse.ArgumentParser) – The argparse parser to add arguments to.
- Return type:
None
- create_manager_instance(args)¶
Create a new
MlManagerinstance.- Parameters:
args (argparse.Namespace) – Parsed command-line arguments.
- Returns:
Instance initialized with CLI arguments and app config.
- Return type:
- get_actions()¶
Return the list of valid actions for the ML Provisioner CLI.
- get_actions_help()¶
Return help text describing all available actions.
- Returns:
Formatted help text for all ML Provisioner actions
- Return type:
- 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:
- get_manager_class()¶
Return the manager class for this CLI.
- is_action_required()¶
Determine if an action argument is required for this CLI.
- Returns:
Always True for this CLI
- Return type:
- ml_provisioner.cli.main()¶
Entry point for ML Provisioner CLI.
Validates AWS Marketplace license before running the CLI. Exits with code 1 if license validation fails.
- Returns:
None