Skip to main content

FORKED for 4dn-dcic. Use to package and deploy lambda functions.

Project description

======== python-λ

.. image:: https://img.shields.io/pypi/v/python-lambda.svg :alt: Pypi :target: https://pypi.python.org/pypi/python-lambda/

.. image:: https://travis-ci.org/4dn-dcic/python-lambda.svg?branch=master :alt: Build Status :target: https://travis-ci.org/4dn-dcic/python-lambda

.. image:: https://coveralls.io/repos/github/4dn-dcic/python-lambda/badge.svg?branch=master :alt: Coverage :target: https://coveralls.io/github/4dn-dcic/python-lambda?branch=master

Python-lambda is a toolset for developing and deploying serverless Python code in AWS Lambda.

Important

This is a FORK of the original Python-lambda package by Nick Ficano. It will NOT be updated regularly and is frozen per our projects needs.

Description

AWS Lambda is a service that allows you to write Python, Java, or Node.js code that gets executed in response to events like http requests or files uploaded to S3.

Working with Lambda is relatively easy, but the process of bundling and deploying your code is not as simple as it could be.

The Python-Lambda library takes away the guess work of developing your Python-Lambda services by providing you a toolset to streamline the annoying parts.

Requirements

  • Python 3.6
  • Pip (Any should work)
  • Virtualenv (>=15.0.0)
  • Virtualenvwrapper (>=4.7.1)

Getting Started

Using this library is intended to be as straightforward as possible. Code for a very simple lambda used in the tests is reproduced below.

.. code:: python

config = { 'function_name': 'my_test_function', 'function_module': 'service', 'function_handler': 'handler', 'handler': 'service.handler', 'region': 'us-east-1', 'runtime': 'python3.6', 'role': 'helloworld', 'description': 'Test lambda' }

def handler(event, context): return 'Hello! My input event is %s' % event

This code illustrates the two things required to create a lambda. The first is config, which specifies metadata for AWS. One important thing to note in here is the role field. This must be a IAM role with Lambda permissions - the one in this example is ours. The second is the handler function. This is the actual code that is executed.

Given this code in example_function.py you would deploy this function like so:

.. code:: python

from aws_lambda import deploy_function import example_function deploy_function(example_function, function_name_suffix='', package_objects=['list', 'of', 'local', 'modules'], requirements_fpath='path/to/requirements', extra_config={'optional_arguments_for': 'boto3'})

And that's it! You've deployed a simple lambda function. You can navigate to the AWS console to create a test event to trigger it or you can invoke it directly using Boto3.

Advanced Usage

Many of the options specified in the above code block when it came to actually deploying the function are not used. These become more useful as you want to make more complicated lambda functions. The ideal way to incorporate dependencies into lambda functions is by providing a requirements.txt file. We rely on pip to install these packages and have found it to be very reliable. While it is also possible to specify local modules as well through package_objects, doing so is not recommended because those modules must be specified at the top level of the repository in order to work out of the box. There is a comment on this topic in example_function_package.py with code on how to handle it.

Tests

Tests can be found in the test_aws_lambda.py. Using the tests as a guide to develop your lambdas is probably a good idea. You can also see how to invoke the lambdas directly from Python (and interpret the response).

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

python-lambda-4dn-1.0.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

python_lambda_4dn-1.0.0-py3.6.egg (13.4 kB view details)

Uploaded Egg

python_lambda_4dn-1.0.0-py2.py3-none-any.whl (14.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file python-lambda-4dn-1.0.0.tar.gz.

File metadata

  • Download URL: python-lambda-4dn-1.0.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.5

File hashes

Hashes for python-lambda-4dn-1.0.0.tar.gz
Algorithm Hash digest
SHA256 279dd137da96da5d3672f8ab1c50c50dad5eb216ac0d71936bf83ab38f63d333
MD5 ff83b0bd4016191383a42a6fccc81703
BLAKE2b-256 1cfbe4fc4773e84699b1e3d80b0c2958d9c875c65095a1ae7ca71014c0d66d11

See more details on using hashes here.

File details

Details for the file python_lambda_4dn-1.0.0-py3.6.egg.

File metadata

  • Download URL: python_lambda_4dn-1.0.0-py3.6.egg
  • Upload date:
  • Size: 13.4 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.5

File hashes

Hashes for python_lambda_4dn-1.0.0-py3.6.egg
Algorithm Hash digest
SHA256 0e43c1bbccf41a7f95ed19268acb12076663a0b6ff614bd7e72ee60e96bf22f1
MD5 d4773ad1c070ada42b981dee2d706da5
BLAKE2b-256 fc7200cd769341e3a1193556da14b79866f69cb8242dd828041c254965bcede7

See more details on using hashes here.

File details

Details for the file python_lambda_4dn-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: python_lambda_4dn-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.5

File hashes

Hashes for python_lambda_4dn-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cf289a8f13e3afb45f0f8bb429dcd456d1261acb2804bc08716d528f033a6a09
MD5 785ee1652699bc9c905245d52fc2bcb7
BLAKE2b-256 0ea8c8c3aa625094002a75255ade42049b732bef1b61cb6c521b944c86fc1fd6

See more details on using hashes here.

Supported by

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