Package: lambdex
lambdexlambdex turns pex files into aws lambda functions.pexis a tool that simplifies packaging python environments and is ideally suited
for aws lambda.  lambdex takes pex files and turns them into aws lambda functions, allowing
you to more easily run complex applications in the cloud.aws lambda documentation and concepts can be foundhere.using the lambdex cliThe lambdex cli has two subcommands:buildandtest.buildfurther has two possible modes of operation: by specifying
an entry point that already exists within the pex file (-e) or by specifying an external script and handler to embed within
the pex file (-s/-H).step 1: package a pex fileFirst you must package a pex file.  Assuming you already have thepextool
and a requirements.txt, you can simply runpex -r requirements.txt -o lambda_function.pexto produce a pex file containing the requirements.  If you must build a pex
file with platform-specific extensions, see the tips section below for more
information about building Amazon Linux-specific extensions.step 2: add lambdex handlerThis can be done one of two ways, depending on where your code lives.If you have a handler function named 'handler' in package
'mymodule.myapp' that is already contained within lambda_function.pex,
then you can simply runlambdex build -e mymodule.myapp:handler lambda_function.pexIf you have a script function.py with a lambda handler namedmy_handler, you would instead runlambdex build -s function.py -H my_handler lambda_function.pexThis bundles function.py within the pex environment and instructs lambdex to
call the python functionmy_handlerwhen being invoked by AWS.If you would like to build a GCP Cloud Function, you will need to specify the name of the entrypoint module
to bemain.py.lambdex build -s example_http_function.py -M main.py lambda_function.zipstep 3 (optional): test your lambdex functionOnce you have created a lambdex file, you can test it as if it were being invoked by Amazon usinglambdex test.
Given a lambdex packagelambda_function.pex, you can either send it an empty json event usinglambdex test --empty lambda_function.pexYou can alternately supply a list of files containing json structs e.g.lambdex test lambda_function.pex event1.json event2.json ...Testing a GCP HTTP Cloud Function requires specifying the type.lambdex test --type gcp-http lambda_function.zipNote: In order to test GCP HTTP Cloud Functions, you must be using pex v1.6 or greater.step 4: upload lambda functionYou can create/update lambda functions via the AWS Console, or you can do it
via the CLI usingaws lambda create-functionoraws lambda update-function-coderespectively.NOTE: When creating the function, you must specify the AWS Lambda handler aslambdex_handler.handler.  Via the CLI, this is the--handlerflag.  This
is the wrapper injected by lambdex that manages invocation of your code.Do not confuse this with the-Hoption tolambdex build.tipsbuilding amazon linux pex filesMost simple dependencies have no platform-specific extensions and thus can be built anywhere.  However there are a number of
popular packages (e.g. numpy, scipy, matplotlib, PIL, ...) that require building C extensions that can prove tricky
to get packaged correctly.Amazon provides an amazonlinux docker image which can be useful for building platform-specific extensions to run
on AWS Lambda.  Seedocumentationfor information about that image.The minimum Dockerfile to produce can environment that can build Amazon Linux-specific pex files can be foundherecontrolling runtime executionTo override the entry point that was specified at build time, you can use theLAMBDEX_ENTRY_POINTenv var:LAMBDEX_ENTRY_POINT=mymodule.myapp:other_handler ...