Better AWS Lambda handlers.
Project description
muttons
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 mutton.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 mutton
import mutton
class EchoHandler(mutton.Handler):
"""Echo handler."""
def perform(self, request, **k):
"""Echo perform method."""
response = mutton.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
mutton.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 mutton.apig
submodule as an example of implementing more event sources.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mutton-0.0.5.tar.gz
.
File metadata
- Download URL: mutton-0.0.5.tar.gz
- Upload date:
- Size: 5.5 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b16ad8ac4e029e5d3fb862c9caf45438a87a632a0ac5420b3e4e91f14ad20e3 |
|
MD5 | 2b1782f01997278c401b631a898260fc |
|
BLAKE2b-256 | 8d3f361a058a6ecd87b0b46835d037d20d73e5f51fa4b71df6f12d828ead95cd |
File details
Details for the file mutton-0.0.5-py2.py3-none-any.whl
.
File metadata
- Download URL: mutton-0.0.5-py2.py3-none-any.whl
- Upload date:
- Size: 9.6 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | d23b3c4580fa0b0ea4ea7b5c841e9168c019ed25beb6f304a344b8e14a6f41c3 |
|
MD5 | 439b9c7997b3f8a5dd9f01ebe5a5568b |
|
BLAKE2b-256 | 8c0f17d5d23181cac6772f819ac8a4f279b2ddcd5f9105e483098efeeee0b0ca |