Skip to main content

python-λ

Pypi Build Status Coverage

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.

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:

from aws_lambda import deploy_function
import example_function
deploy_function(example_function,
                function_name_suffix='<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).

Metadata

Release files for python-lambda-4dn 1.0.1

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

Source distribution (sdist)

Source distribution for python-lambda-4dn 1.0.1
File Size Uploaded
python-lambda-4dn-1.0.1.tar.gz 10.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for python-lambda-4dn 1.0.1
File Interpreter ABI Platform
python_lambda_4dn-1.0.1-py3.6.egg Legacy Egg format - - Details
python_lambda_4dn-1.0.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 39.1 kB

Release files / python-lambda-4dn-1.0.1.tar.gz

Download URL python-lambda-4dn-1.0.1.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9661582b571a0478f7701c22a7edcb871e7bf21f20df04aeb63b2ad953f122b8
BLAKE2b-256 checksum
How to use checksums
9f9b64c9d6a09d9937d320fb31858f09708dcb73b1e2cb9a5aeedcb103ce4c95
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / python_lambda_4dn-1.0.1-py3.6.egg

Download URL python_lambda_4dn-1.0.1-py3.6.egg
Size 13.4 kB
Tags Egg
SHA-256 checksum
How to use checksums
947a698643d413c4a679f0b36248be947559069d311836f7404327fc27374277
BLAKE2b-256 checksum
How to use checksums
6daea3000c59c70b20a453a8d322bbc11943ecca65018185e820d9930dabaab9
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / python_lambda_4dn-1.0.1-py2.py3-none-any.whl

Download URL python_lambda_4dn-1.0.1-py2.py3-none-any.whl
Size 14.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
8976ad35a83b7a5a481571b62f18c9de8aec1da6508b3e9832dc4c70292a729b
BLAKE2b-256 checksum
How to use checksums
36848ed832da82c3ba5f7393cca9c391946c4153c812c15d219af8e38d732c33
Upload date
Uploaded using Trusted Publishing?
What is 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
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