Skip to main content

Lambdex turns pex files into aws lambda python functions.

Project description

lambdex

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.

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

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

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

lambdex-0.1.4.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

lambdex-0.1.4-py2.py3-none-any.whl (11.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file lambdex-0.1.4.tar.gz.

File metadata

  • Download URL: lambdex-0.1.4.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for lambdex-0.1.4.tar.gz
Algorithm Hash digest
SHA256 189e3f7aa492fd3653a6dcafb7bb493d2fa60a32f6ab8122c2ee53feb97967cc
MD5 2165220ded53b2bc85216c8d0eb37fdf
BLAKE2b-256 15f2e047a35bf373b12e00bae7d50d465fa73e003f5c03afee6b46ffa1799acc

See more details on using hashes here.

File details

Details for the file lambdex-0.1.4-py2.py3-none-any.whl.

File metadata

  • Download URL: lambdex-0.1.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for lambdex-0.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 51e4e92a20cf1472e560b7b5a927286308d9e6252261a79d94b8549a3ba39bd3
MD5 1f4a47dc7fdfe46496881a4d04fa6644
BLAKE2b-256 0d9f288d20bcca274fe3d9242351560eb1c19a3bac12c3c5c5008f35c1f559ef

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page