builder

Lambda layer building implementation - Step 1 of the layer creation workflow.

class aws_lambda_artifact_builder.layer.builder.BasedLambdaLayerLocalBuilder(verbose: bool = True, printer: ~typing.Callable[[str], None] = <built-in function print>, path_pyproject_toml: ~pathlib.Path = REQ, credentials: ~aws_lambda_artifact_builder.layer.foundation.Credentials | None = None, skip_prompt: bool = False, _build_tool: ~aws_lambda_artifact_builder.constants.LayerBuildToolEnum = REQ)[source]

Base command class for local Lambda layer builds.

This abstract base implements a standardized 4-step workflow for building Lambda layers directly on the host machine using local dependency management tools (pip, Poetry, UV). The command pattern design allows fine-grained control and customization of each build phase.

4-Step Build Workflow:

  1. Preflight Check (step_1_preflight_check()): Validate environment, tools, and project structure

  2. Prepare Environment (step_2_prepare_environment()): Clean build directories and set up workspace

  3. Execute Build (step_3_execute_build()): Run tool-specific dependency installation (abstract)

  4. Finalize Artifacts (step_4_finalize_artifacts()): Transform output into Lambda-compatible structure

Command Pattern Benefits:

  • Each step can be overridden independently for customization

  • Sub-steps within each phase provide granular control points

  • Workflow can be extended with pre/post hooks or additional steps

  • Easy to test individual phases in isolation

Local Build Advantages:

  • Fast execution without Docker overhead

  • Direct access to host environment and tools

  • Ideal for development iteration and Linux environments

  • Simple dependency resolution using host-installed package managers

Usage: Subclass and implement step_3_execute_build() with tool-specific logic. Call run() to execute the complete workflow, or invoke individual steps for custom workflows.

property path_layout: LayerPathLayout

LayerPathLayout object for managing build paths.

run()[source]

Execute the complete local build workflow in sequence.

Runs all four build phases in order. Override individual steps or call steps directly for custom workflows.

step_1_preflight_check()[source]

Perform read-only validation of build environment and project configuration.

step_2_prepare_environment()[source]

Set up necessary prerequisites for the build process.

step_3_execute_build()[source]

Execute dependency manager-specific installation commands (pip/poetry/uv).

step_4_finalize_artifacts()[source]

Transform build output into Lambda layer’s required python/ directory structure.

step_1_1_print_info()[source]

Display build configuration and paths.

Provides visibility into the build process by showing which tool is being used and where artifacts will be created.

step_2_1_setup_build_dir()[source]

Prepare the build environment by cleaning and creating directories.

Ensures a clean slate for layer creation by removing previous artifacts and establishing the required directory structure.

Parameters:

skip_prompt – If True, automatically remove existing build directory

class aws_lambda_artifact_builder.layer.builder.BasedLambdaLayerContainerBuilder(verbose: bool = True, printer: ~typing.Callable[[str], None] = <built-in function print>, path_pyproject_toml: ~pathlib.Path = REQ, py_ver_major: int = REQ, py_ver_minor: int = REQ, is_arm: bool = REQ, path_script: ~pathlib.Path = REQ, credentials: ~aws_lambda_artifact_builder.layer.foundation.Credentials | None = None)[source]

Base command class for containerized Lambda layer builds.

This abstract base implements a standardized 4-step workflow for building Lambda layers inside Docker containers using official AWS SAM build images. The containerized approach ensures perfect runtime compatibility while maintaining the same command pattern flexibility.

4-Step Containerized Workflow:

  1. Preflight Check (step_1_preflight_check()): Validate Docker environment and build prerequisites

  2. Prepare Environment (step_2_prepare_environment()): Copy build scripts and set up credentials

  3. Execute Build (step_3_execute_build()): Run Docker container with mounted volumes

  4. Finalize Artifacts (step_4_finalize_artifacts()): Clean up temporary files and validate results

Container Build Process:

  • Mounts project root to /var/task inside container

  • Executes tool-specific build script within Lambda runtime environment

  • Uses local builder classes inside container for consistency

  • Transfers credentials securely via JSON files

Architecture Benefits:

  • Runtime Compatibility: Uses official AWS Lambda container images

  • Cross-Platform: Builds Linux-compatible layers on any host OS

  • Isolation: No interference with host Python environment

  • Reproducibility: Identical results across different development machines

  • Architecture Support: Handles both x86_64 and ARM64 Lambda runtimes

Command Pattern Benefits:

  • Individual container setup steps can be customized

  • Easy to extend with additional pre/post processing

  • Docker configuration can be modified through property overrides

  • Build script deployment can be customized per tool

Usage: Subclass and provide tool-specific build script via path_script. Call run() to execute containerized build, or customize individual steps as needed.

property path_layout: LayerPathLayout

LayerPathLayout object for managing build paths.

property image_tag: str

Docker image tag based on target architecture.

Returns:

Architecture-specific tag for AWS SAM build images

property image_uri: str

Full Docker image URI for AWS SAM build container.

Uses official AWS SAM images that match the Lambda runtime environment to ensure compatibility between local builds and deployed functions.

Returns:

Complete Docker image URI from AWS public ECR

property platform: str

Docker platform specification for target architecture.

Returns:

Platform string for docker run –platform argument

property container_name: str

Unique container name for the build process.

Includes Python version and architecture to avoid conflicts when running multiple builds concurrently.

Returns:

Descriptive container name for docker run –name argument

property docker_run_args: list[str]

Complete Docker run command arguments.

Constructs the full command for executing the build script inside a Docker container with proper volume mounting and platform specification.

Returns:

List of command arguments for subprocess execution

run()[source]

Execute the complete containerized build workflow in sequence.

Runs all four container build phases in order. Override individual steps or call steps directly for custom workflows.

step_1_preflight_check()[source]

Validate Docker environment and container build prerequisites.

step_2_prepare_environment()[source]

Set up container build prerequisites including scripts and credentials.

step_3_execute_build()[source]

Run Docker container with AWS SAM build image for dependency installation.

step_4_finalize_artifacts()[source]

Clean up temporary files and validate container build results.

step_2_1_copy_build_script()[source]

Copy the tool-specific container build script to the project directory.

Subclasses must implement this method to provide the appropriate build script that will be executed inside the Docker container.

step_2_2_setup_private_repository_credential()[source]

Configure private repository authentication (optional).

Subclasses can override this method to set up credentials for accessing private PyPI servers or corporate package repositories.

step_3_1_docker_run()[source]

Execute the Docker container build process.

Runs the configured Docker command to build the Lambda layer inside the container environment.