Skip to main content

Better AWS Lambda handlers.

Project description

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.

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

aws-lambda-handler-0.0.4.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

aws_lambda_handler-0.0.4-py2.py3-none-any.whl (7.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file aws-lambda-handler-0.0.4.tar.gz.

File metadata

  • Download URL: aws-lambda-handler-0.0.4.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for aws-lambda-handler-0.0.4.tar.gz
Algorithm Hash digest
SHA256 0b8e9ec830341687098648f958e5de7fbffcfd9979deaee5778b35c184939450
MD5 4af8b2b077e9bca7abdf4b935ebe27f9
BLAKE2b-256 360563bf99ce53703e8a70883c4bcfcf68c95a8b50f199c23ce735e8bd712b95

See more details on using hashes here.

File details

Details for the file aws_lambda_handler-0.0.4-py2.py3-none-any.whl.

File metadata

  • Download URL: aws_lambda_handler-0.0.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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

File hashes

Hashes for aws_lambda_handler-0.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0a01707ff5a29d55fb1538e7a6aeb454607398baaeaa5f9f85e085fae5481899
MD5 9c7b43d8f36d84df894e96c6dc614b31
BLAKE2b-256 14ea634bb11f92cd6c51f885387744e565f948bfc4f1d9efacf9e2667ed01cec

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