Skip to main content

CircleCI codecov

aws-lambda-handlers

Better Python 3 AWS Lambda Handlers.

Currently, your only choice for making Python handlers for AWS Lambda is to create a function like so:

def handler(event, context):
    return True

This isn't ideal when you start dealing with more than one handler, or if you want to provide a configurable and reusable handler. This package provides three base classes, the Handler, the Request, and the Response handler.

The Handler class is a callable, you create a subclass off of this, instantiate it, and that's what you configure AWSλ to invoke.

Your Handler has to have a perform(self, request) method, this houses your handler's business logic, Handler.__call__ executes this function and expects a Response object.

The Response object behaves like a dictionary and an object, an attribute called serialized is returned to AWSλ.

The request argument in perform(self, request) is a Request object, and it houses the event and context parameters that AWSλ passes to your handler. Packaging those handler arguments into an object makes them available for transparent mutations, see aws_lambda.apig.APIGatewayRequest for reference.

The foundation of this library is tiny, I recommend reviewing the main classes to further understand how to use this package.

Usage

pip install aws-lambda-handler
import aws_lambda

class EchoHandler(aws_lambda.Handler):
    """Echo handler."""

    def perform(self, request, **k):
        """Echo perform method."""
        response = aws_lambda.Response()
        response.body = self.request.event
        return response

echo_handler = EchoHandler()

# `echo_handler` is now a callable function you can map your AWS Lambda function to

Develop

Fork this library and send over PRs, I will consider applications for contributors if two of your PRs gets merged and published.

pipenv sync --dev # setup
pipenv run pytest # test

Supported Event Sources

  • API Gateway aws_lambda.apig
  • S3
  • DynamoDB
  • SNS
  • SES
  • SQS
  • Cognito
  • Cloudwatch Logs, Events

Help

We want support for more event sources, I am willing to entertain PRs. You can use the aws_lambda.apig submodule as an example of implementing more event sources.

Metadata

Release files for aws-lambda-handler 0.0.4

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

Source distribution (sdist)

Source distribution for aws-lambda-handler 0.0.4
File Size Uploaded
aws-lambda-handler-0.0.4.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-lambda-handler 0.0.4
File Interpreter ABI Platform
aws_lambda_handler-0.0.4-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 13.0 kB

Release files / aws-lambda-handler-0.0.4.tar.gz

Download URL aws-lambda-handler-0.0.4.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0b8e9ec830341687098648f958e5de7fbffcfd9979deaee5778b35c184939450
BLAKE2b-256 checksum
How to use checksums
360563bf99ce53703e8a70883c4bcfcf68c95a8b50f199c23ce735e8bd712b95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.4

Release files / aws_lambda_handler-0.0.4-py2.py3-none-any.whl

Download URL aws_lambda_handler-0.0.4-py2.py3-none-any.whl
Size 7.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0a01707ff5a29d55fb1538e7a6aeb454607398baaeaa5f9f85e085fae5481899
BLAKE2b-256 checksum
How to use checksums
14ea634bb11f92cd6c51f885387744e565f948bfc4f1d9efacf9e2667ed01cec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.4

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

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