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.2.tar.gz (5.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.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lambda-pkg-resources-0.0.2.tar.gz
  • Upload date:
  • Size: 5.4 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.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.6

File hashes

Hashes for lambda-pkg-resources-0.0.2.tar.gz
Algorithm Hash digest
SHA256 03fdafe2dd897cff24090dda8f9441bbe9ce94bb8b020fcba08ec50981aadeb9
MD5 fd60e7d0b1d65c0b78856de64195e219
BLAKE2b-256 6788955bdb2ffc31a4bb064a8d811412938fc84b2cb0dcd7e1ea71ec7a343e88

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lambda_pkg_resources-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.6 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.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.6

File hashes

Hashes for lambda_pkg_resources-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e5e6294488ec18efc3ccc0ab3207c60b96428be08e27dd1e6d873e01bb29ed0d
MD5 a014c2607943e8fe8c742053c5070491
BLAKE2b-256 2c1da4fc2ad0854545ce7f6cf9fb2b807c7f3c163f155f137c346f51e9436c2d

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