Skip to main content

Supports a dist-info installation of packages with package exclusions

Project description

lambda-pkg-resources

An extension to pkg_resources that provides for dist-info (standard whl) installation of packages and for exclusion of unwanted or unnecessary packages

The AWS Lambda execution environment inherently provides a number of Python packages, with the two most important of these being boto3 and botocore. The combination of these (and their dependencies) are several MB of package storage.

Many of the Python open-source packages built to work with AWS install_requires the boto3 package. While this is appropriate for non-Lamdba usage, it presents two problems when used in a Lambda function.

The first problem is bloat of the Lambda function package, leading to longer cold-start times and an inability to use the Lambda console to manage the code in the function.

The second problem is that the version of boto3 included in the Lambda package necessarily "drifts" from the version of the AWS API that it is attempting to call. This can lead to strange errors where the Lambda function starts throwing strange errors or simply failing to execute appropriately (sometimes with no exceptions thrown).

This library allows for the programatic creation of Lambda funciton and layer packages that install what is required for the function/layer to run while excluding, anywhere within the dependency tree, the Python packages that are already provided by the AWS Lambda execution environment. It can additionally be used programatically to exclude packages in other execution environments if desired.

This library provides three components that work in conjunction with the standard pkg_resources Python package to perform a dist-info install of dependent packages and allow for exclusion of packages that are not desired.


LAMBDA_EXCLUDES

A global variable that is a set of the current package names provided by the AWS Lambda execution environment.


ExcludesWorkingSet

Extends WorkingSet and performs a dist-info install of packages via the overridden resolve method.


DistInstaller

An installer to that can be used in the resolve method of either WorkingSet or ExcludesWorkingSet through the use of the fetch_dist method.


Example Usage

from lambda_pkg_resources import DistInstaller, ExcludesWorkingSet, LAMBDA_EXCLUDES
from pkg_resources import parse_requirements

ws = ExcludesWorkingSet(
    entries=["package/install/directory"],
    excludes={"six"},
)
di = DistInstaller("package/install/directory")
ws.resolve(
    parse_requirements(["watchtower", "python-jose"]), installer=di.fetch_dist, replace_conflicting=True
)

This will install watchtower and python-jose in "packages/install/directory", excluding the package six anywhere it is found in the dependency tree.


This package is used in lambda-setuptools to remove all of the libraries listed in LAMBDA_EXCLUDES from the built package or library using the ldist command.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lambda-pkg-resources-0.0.4.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lambda_pkg_resources-0.0.4-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file lambda-pkg-resources-0.0.4.tar.gz.

File metadata

  • Download URL: lambda-pkg-resources-0.0.4.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for lambda-pkg-resources-0.0.4.tar.gz
Algorithm Hash digest
SHA256 9cce78d231c72cbe8f6e56897e738683321aa39241476f5bb2e26dc96a7c8976
MD5 df07d52deab0f2bbc043da59aa2bb8ad
BLAKE2b-256 81e8a91649c8371af7fec732b987d7dc53468394e4ae3599025b64fdcdb68311

See more details on using hashes here.

File details

Details for the file lambda_pkg_resources-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: lambda_pkg_resources-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for lambda_pkg_resources-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3615abbde354f2852144b0b57b8da1faa79de26f85ca7969ce51bcc611111d2f
MD5 95879ddb231ac50a7f7f458900c0ce6b
BLAKE2b-256 b2eb8e2bf91884250ff44da4205eea69d2cd845e0f34a810b99da7868b9a493c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page