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
Built Distribution
File details
Details for the file lambda-pkg-resources-0.0.6.tar.gz
.
File metadata
- Download URL: lambda-pkg-resources-0.0.6.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 925029376b81083feb16792200036196aac286b0e26063174864b50304a54793 |
|
MD5 | eba730334a6273a34556c23d481638c8 |
|
BLAKE2b-256 | b454512ccb2f04d0c0059272e5ff9eca61175ca6182b594e2cf05b76e5d0018e |
File details
Details for the file lambda_pkg_resources-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: lambda_pkg_resources-0.0.6-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 558a38c05fcfb6cf8858ed0bc6a8a0fce989f36c09c04215b1c379025e5f5470 |
|
MD5 | 9506d47eca94e761efd089773995d3fc |
|
BLAKE2b-256 | 7d90fe1480032cefc036b71a841706ac7e6b63697e803d279c6c73f898c2e236 |