Implement layout="zip" for Lambda/GCF, deprecating lambdex (Cherry-pick of #19076) #19120
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes #18879 by allowing the
python_awslambda
andpython_google_cloud_function
FaaS artefacts to be generated in "simple" format, using thepex3 venv create --layout=flat-zipped
functionality recently added in PEX 2.1.135 (https://github.com/pantsbuild/pex/releases/tag/v2.1.135).This format is just: put everything at the top-level. For instance, the zip contains
cowsay/__init__.py
etc., rather than.deps/cowsay-....whl
. This avoids the need to do the dynamic PEX initialisation/venv creation.This shifts the dynamic dependency computation/extraction/layout from run-time to build-time, relying on the FaaS environment to be generally consistent. It shouldn't change what actually happens after initialisation. This can:
.bootstrap/
folder seems to be about 2MB uncompressed, ~1MB compressed).For instance, for one Python 3.9 Lambda in our codebase:
(The PEX-postprocessing time metric is specifically the time to run the
Setting up handler
(lambdex) orBuild python_awslambda
(pex3 venv create
) process, computed by runningpants --keep-sandboxes=always package ...
for each layout, and thenhyperfine -r3 -w1 path/to/first/__run.sh path/to/second/__run.sh
. This doesn't include the time to construct the input PEX, which is the same for both.)This functionality is driven by adding a new option to the
[lambdex].layout
option added in #19074. In #19074 (targeted for 2.17), it defaultslambdex
(retaining the current code paths). This PR flips the default to the new optionzip
, which keys into the functionality above. I've tried to keep the non-lambdex implementation generally separate to the lambdex one, rather than reusing all of the code that happens to be common currently, because it'd make sense to deprecate/remove the lambdex functionality and thus I feel it's best for this new functionality to be mostly a fresh start.This PR's commits can be reviewed independently.
I think this is an acceptable MVP for this functionality, but there's various bits of follow-up:
files
being loaded into these packages, which has been temporarily lost (Warn aboutfiles()
in PEXes in one place #19027)complete_platforms
for serverless/FaaS environmentsruntime
#18195 and Allow building AWS Lambda Layers #18880pex3 venv create ...
could use the lock file and sources to directly compute the appropriate files, without having to materialise a normal pex firstThis is a re-doing of #19022 with a simpler approach to deprecation, as discussed in #19074 (comment) and #19032 (comment). The phasing will be:
layout = "lambdex"
is implicit, tell people to set it: recommendzip
, but allowlambdex
if they have tolayout = "lambdex"
is set at all, tell people to remove it and switch tozip
[lambdex]
section entirely)