Skip to main content

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 handler
  • context - the context from the aws handler
  • response - the handler response, if any
  • exception - during error handler you can have access to this key which contains the exception which triggered the error

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

pymiddy-0.1.0.tar.gz (2.8 kB view hashes)

Uploaded Source

Built Distribution

pymiddy-0.1.0-py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 3

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