aws_lambda_python_packager package

Subpackages

Submodules

aws_lambda_python_packager.arrow_fetcher module

aws_lambda_python_packager.arrow_fetcher.fetch_arrow_package(output_dir: str | Path, package_version: str, python_version='3.9', arch='x86_64')[source]
aws_lambda_python_packager.arrow_fetcher.get_arrow_version(arrow_version: str, python_version: str, arch: str) str | None[source]
aws_lambda_python_packager.arrow_fetcher.open_zip_file(url: object) Generator[TarFile, None, None][source]

aws_lambda_python_packager.dep_analyzer module

exception aws_lambda_python_packager.dep_analyzer.CommandNotFoundError[source]

Bases: Exception

class aws_lambda_python_packager.dep_analyzer.DepAnalyzer(project_root: str | PathLike | None, python_version: str = '3.9', architecture: str = 'x86_64', region: str = 'us-east-1', ignore_packages=False, update_dependencies=False, additional_packages_to_ignore: dict | None = None)[source]

Bases: ABC

analyzer_name : str
backup_files(files: Iterable[str])[source]
copy_from_target(dst: str | PathLike)[source]
copy_from_temp_dir(files: Iterable[str])[source]
copy_to_temp_dir(files: Iterable[str])[source]
abstract direct_dependencies() dict[str, str][source]
export_requirements()[source]
exported_requirements()[source]
property extra_lines
get_layer_files()[source]
get_requirements() Iterable[PackageInfo | ExtraLine][source]
install_dependencies(quiet=True)[source]
install_root()[source]
property pkgs_to_ignore
property pkgs_to_ignore_dict
property pkgs_to_ignore_info
classmethod process_requirements(requirements: Iterable[str]) Iterable[PackageInfo | ExtraLine][source]
project_root : Path
property requirements : dict[str, aws_lambda_python_packager.dep_analyzer.PackageInfo]
run_command(*args, return_state=False, quiet=False, prefix=None, context=None) bool | tuple[str, str][source]
run_pip(*args, return_state=False, quiet=False, context=None)[source]
update_dependency_file()[source]
class aws_lambda_python_packager.dep_analyzer.ExtraLine(iterable=(), /)[source]

Bases: list

class aws_lambda_python_packager.dep_analyzer.PackageInfo(name, version, version_spec)

Bases: tuple

Create new instance of PackageInfo(name, version, version_spec)

name

Alias for field number 0

version

Alias for field number 1

version_spec

Alias for field number 2

aws_lambda_python_packager.lambda_packager module

AWS Lambda Packager

This script is used to package the lambda function code into a zip file. It is an alternative to sam build and uses poetry to manage dependencies.

class aws_lambda_python_packager.lambda_packager.LambdaPackager(project_path: str | PathLike, output_dir: str | PathLike, python_version: str = '3.9', architecture: str = 'x86_64', region: str = 'us-east-1', update_dependencies: bool = False, ignore_packages: bool = False, split_layer: bool = False, additional_packages_to_ignore: dict | None = None, ignore_unsupported_python: bool = True)[source]

Bases: object

Initialize the Lambda Packager

Parameters:
project_path: str | PathLike

Path to the pyproject.toml file

python_version: str = '3.9'

Python version to target

architecture: str = 'x86_64'

Architecture to target (x86_64 or arm64)

region: str = 'us-east-1'

AWS region to target

update_dependencies: bool = False

whether to update pyproject.toml with the appropriate versions of packages from the AWS lambda environment (ignored if ignore_packages is False)

ignore_packages: bool = False

Ignore packages that already exist in the AWS lambda environment

compile_python()[source]
compress_boto()[source]
get_aws_wrangler_pyarrow()[source]
get_total_size()[source]
layer_dir : str | PathLike | None
package(no_clobber: bool = False, zip_output: bool | str = False, compile_python: bool = False, use_wrangler_pyarrow: bool = False, strip_tests: bool = False, strip_libraries: bool = False, strip_python: bool = False, strip_other_files: bool = False, compress_boto: bool = False)[source]
set_utime(set_time: int | None = None)[source]
strip_libraries()[source]
strip_other_files()[source]
strip_python()[source]
strip_tests()[source]
zip_output(zip_output)[source]
exception aws_lambda_python_packager.lambda_packager.ProjectTypeException[source]

Bases: Exception

exception aws_lambda_python_packager.lambda_packager.UnsupportedVersionException[source]

Bases: Exception

aws_lambda_python_packager.lambda_packager.get_strip_binary(architecture='x86_64')[source]
aws_lambda_python_packager.lambda_packager.sizeof_fmt(num, suffix='B')[source]

aws_lambda_python_packager.pip_analyzer module

class aws_lambda_python_packager.pip_analyzer.PipAnalyzer(project_root: str | PathLike | None, python_version: str = '3.9', architecture: str = 'x86_64', region: str = 'us-east-1', ignore_packages=False, update_dependencies=False, additional_packages_to_ignore: dict | None = None)[source]

Bases: DepAnalyzer

analyzer_name : str = 'pip'
direct_dependencies() dict[str, str][source]
property extra_lines
aws_lambda_python_packager.pip_analyzer.get_packages(path)[source]

aws_lambda_python_packager.poetry_analyzer module

class aws_lambda_python_packager.poetry_analyzer.PoetryAnalyzer(project_root: str | PathLike | None, python_version: str = '3.9', architecture: str = 'x86_64', region: str = 'us-east-1', ignore_packages=False, update_dependencies=False, additional_packages_to_ignore: dict | None = None)[source]

Bases: DepAnalyzer

analyzer_name : str = 'poetry'
direct_dependencies() dict[str, str][source]
install_root()[source]
load_toml() dict[source]
lock()[source]
locked()[source]
run_poetry(*args, return_state=False, quiet=False, context=None)[source]

aws_lambda_python_packager.util module

aws_lambda_python_packager.util.chdir_cm(path: str | PathLike)[source]
aws_lambda_python_packager.util.chgenv_cm(**kwargs)[source]
aws_lambda_python_packager.util.get_glue_libraries()[source]

Gets libraries included in AWS Glue

aws_lambda_python_packager.util.get_python_runtime(architecture='x86_64', target_version=None)[source]

Gets an allowed python runtime for the given architecture

Parameters:
architecture='x86_64'

Architecture to target (x86_64 or arm64)

target_version=None

Python version to target

Returns:

A tuple of (python_version, architecture)

Module contents