<#18879 Construct Python serverless artefacts (AWS...
# github-notifications
c
#18879 Construct Python serverless artefacts (AWS Lambda etc.) in expected layout, without PEX Issue created by huonw Is your feature request related to a problem? Please describe. AWS Lambda (and GCP functions?) are often deployed as zip artefacts in a particular format: all code and dependencies at the top level. This format will likely have the fastest cold starts. For instance: Lambda's docs recommend just splatting all dependencies into the top level of a zip file, along with whatever first party code: https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-create-package-with-dependency (steps 4-6). Currently pants
python_awslambda
and
python_google_cloud_function
use pex+lambdex to build artefacts, which work well, but they do the pex dynamic initialisation on cold start, which, for many of our lambdas, takes about a second. Describe the solution you'd like Use
pex3 venv create --layout=flat-zipped ...
pantsbuild/pex#2140 (in 2.1.135) to export deps/src in the format expected. Notes: • This could naturally also allow
--layout=flat
to support #18282. • This is potentially a breaking change, as it loses the dynamic initialisation that lambdex currently supports: I believe it is currently possible to use
python_awslambda(complete_platforms=[":arm.json", ":x86.json"])
to build a single artefact that runs on multiple lambda platforms (e.g. x86 vs arm there, but also 3.9 vs. 3.10). However, these use-cases can be replaced by `pex_binary`: setting
__pex__.path.to.handler
works now. • It is convenient for deployment that all
python_awslambda
packages have the same entry point (
lambdex_handler.handler
), e.g. our CDK code only needs to know the location of the package and can set
handler: 'lambdex_handler.handler'
automatically, rather than needing to duplicate the entrypoint in the target definition and in the deploy templates. It would be good to retain this in some form, e.g.
__pants_entrypoint.handler
, potentially disableable. • To ease transition, I think the lambdex-based building should be deprecated and continue to be used by default, with global (and per target?) flags to switch over to this new form. Describe alternatives you've considered A new target instead of reusing `python_awslambda`: deprecating the existing functionality over a few releases seems okay? Additional context N/A pantsbuild/pants