Middleware engine for AWS Lambda - Inspired by middyjs
Project description
PyMiddy
Heavily inspired from middyjs.
Quick start
from pymiddy import Middy
from pymiddy.middlewares import CORS
@Middy
def handler(event, context):
return {
'statusCode': 200,
'body': 'lorem ipsum dolor sit amet'
}
handler.use(TestMiddleware(1)) \
.use(CORS({
'credentials': True,
'origins': ['https://website.xyz/']
}))
Custom middlewares
A middleware class should have 3 methods:
class MyCustomMiddleware(object):
def before(self, state):
pass
def after(self, state):
pass
def error(self, state):
pass
The state
contains the following keys:
event
- the event which triggered the lambda function, passed from the aws handlercontext
- the context from the aws handlerresponse
- the handler response, if anyexception
- during error handler you can have access to this key which contains the exception which triggered the error
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
pymiddy-0.1.0.tar.gz
(2.8 kB
view hashes)