Skip to main content

lambdex

[!WARNING] Lambdex is no longer necessary and the 0.2.0 release of Lambdex is the last. Modern PEXes can be used directly as Lambda zips. See the the migration guide for details.

lambdex turns pex files into aws lambda functions.

pex is 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 found here.

using the lambdex cli

The lambdex cli has two subcommands: build and test. build further 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 file

First you must package a pex file. Assuming you already have the pex tool and a requirements.txt, you can simply run

pex -r requirements.txt -o lambda_function.pex

to 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 handler

This 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 run

lambdex build -e mymodule.myapp:handler lambda_function.pex

If you have a script function.py with a lambda handler named my_handler, you would instead run

lambdex build -s function.py -H my_handler lambda_function.pex

This bundles function.py within the pex environment and instructs lambdex to call the python function my_handler when 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 be main.py.

lambdex build -s example_http_function.py -M main.py lambda_function.zip

step 3 (optional): test your lambdex function

Once you have created a lambdex file, you can test it as if it were being invoked by Amazon using lambdex test. Given a lambdex package lambda_function.pex, you can either send it an empty json event using

lambdex test --empty lambda_function.pex

You 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.zip

Note: In order to test GCP HTTP Cloud Functions, you must be using pex v1.6 or greater.

step 4: upload lambda function

You can create/update lambda functions via the AWS Console, or you can do it via the CLI using aws lambda create-function or aws lambda update-function-code respectively.

NOTE: When creating the function, you must specify the AWS Lambda handler as lambdex_handler.handler. Via the CLI, this is the --handler flag. This is the wrapper injected by lambdex that manages invocation of your code.

Do not confuse this with the -H option to lambdex build.

tips

building amazon linux pex files

Most 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. See documentation for information about that image.

The minimum Dockerfile to produce can environment that can build Amazon Linux-specific pex files can be found here

controlling runtime execution

To override the entry point that was specified at build time, you can use the LAMBDEX_ENTRY_POINT env var:

LAMBDEX_ENTRY_POINT=mymodule.myapp:other_handler ...

Metadata

Release files for lambdex 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lambdex 0.2.0
File Size Uploaded
lambdex-0.2.0.tar.gz 17.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lambdex 0.2.0
File Interpreter ABI Platform
lambdex-0.2.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 30.9 kB

Release files / lambdex-0.2.0.tar.gz

Download URL lambdex-0.2.0.tar.gz
Size 17.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1c602f66c9280aef601c967b0f4295cb8ce4ec7b3398bd6cfdc12fcc3d799d5a
BLAKE2b-256 checksum
How to use checksums
bff0cc2bf7781012c53581bd120e9648996262aeb6e53601d9f17efe0d55ec35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release files / lambdex-0.2.0-py2.py3-none-any.whl

Download URL lambdex-0.2.0-py2.py3-none-any.whl
Size 13.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
3a4ba9a75813c9e683fbeb75029327f5daf10312b362d32a512aba3147db5d33
BLAKE2b-256 checksum
How to use checksums
3b6e26f33bdc170687ed61303cc133cfb2b871835e790cdb5bdb5139cb9497ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page