Better 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
Request, and the
Handler class is a callable, you create a subclass off of this, instantiate it, and that's what you configure AWSλ to invoke.
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 behaves like a dictionary and an object, an attribute called
serialized is returned to AWSλ.
request argument in
perform(self, request) is a
Request object, and it houses the
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.
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
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
- [x] API Gateway
- [ ] S3
- [ ] DynamoDB
- [ ] SNS
- [ ] SES
- [ ] SQS
- [ ] Cognito
- [ ] Cloudwatch Logs, Events
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.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size aws_lambda_handler-0.0.4-py2.py3-none-any.whl (7.4 kB)||File type Wheel||Python version py2.py3||Upload date||Hashes View hashes|
|Filename, size aws-lambda-handler-0.0.4.tar.gz (5.6 kB)||File type Source||Python version None||Upload date||Hashes View hashes|
Hashes for aws_lambda_handler-0.0.4-py2.py3-none-any.whl