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.3.tar.gz (5.5 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.3-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lambda-pkg-resources-0.0.3.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for lambda-pkg-resources-0.0.3.tar.gz
Algorithm Hash digest
SHA256 99b32c0e3186783e1ae8083fb055d61c10760b69f74d579bdd1c791fce3a1295
MD5 3b58e85c8b52c1288ddc2065a4f67017
BLAKE2b-256 b5d2988be8a08dea7cb4bc041ac192f571ec99627bc6de07d7d8f82d6464eb64

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lambda_pkg_resources-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for lambda_pkg_resources-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7ad6e897f9ec1df848e386a149516e8cd5f70668b38578de5a5be8d3f2e54e14
MD5 794730ef4a4fcccd0f9f7e581c38af4a
BLAKE2b-256 4e174800380bb1fb8a27ae24baf8b53446e011b3e86555118b129af8f041a166

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