Skip to main content

A collection of useful decorators for making AWS Lambda handlers

Project description

A collection of useful decorators for making AWS Lambda handlers

NOTE: this is in very early stages of development.

lambda_decorators is a collection of useful decorators for writing Python handlers for AWS Lambda. They allow you to avoid boiler plate for common things such as CORS headers, JSON serialization, etc.

These can be used as a library or simply copied and adapted to your needs. If you want to write your own “middlewares” it’s as easy as writing a decorator. The documentation has links to the source of each decorator. They also serve as handy examples for implemenenting your own boilerplate-reducing decorators.

Quick example

# handler.py

from lambda_decorators import cors_headers, json_http_resp, load_json_body

@cors_headers
@json_http_resp
@load_json_body
def handler(event, context):
    return {'hello': event['body']['name']}

When deployed to Lambda behind API Gateway and cURL’d:

$ curl -d '{"name": "world"}' https://example.execute-api.us-east-1.amazonaws.com/dev/hello
{"hello": "world"}

Install

pip install lambda-decorators

Why

Initially, I was inspired by middy which I’ve tried out in JavaScript and was happy with it. So naturally, I thought I’d like to have something similar in Python too. But then as I thought about it more, it seemed that when thinking of functions as the compute unit, when using python, decorators pretty much are middleware! So instead of building a middleware engine and a few middlewares, I just built a few useful decorators.

Included Decorators:

See each individual decorators for specific usage details and the example for some more use cases.


Full API Documentation

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

lambda-decorators-0.1a4.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lambda_decorators-0.1a4-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file lambda-decorators-0.1a4.tar.gz.

File metadata

File hashes

Hashes for lambda-decorators-0.1a4.tar.gz
Algorithm Hash digest
SHA256 a922208a110047e92e815addd8f78fdc380b04d458102652b52968f70544bc46
MD5 0f215df003bc9331dc39c7eab5cb6983
BLAKE2b-256 e1a248dea721a2f2bf221b2391a47378641c39c8d2ef12e2756f9f9c64c6370d

See more details on using hashes here.

File details

Details for the file lambda_decorators-0.1a4-py3-none-any.whl.

File metadata

File hashes

Hashes for lambda_decorators-0.1a4-py3-none-any.whl
Algorithm Hash digest
SHA256 0748e2896ea34401d24446dbf89c789c779d20eba706935a198c05d5b9b029d6
MD5 9a043f4f618ac58ad3f2c18d62160c1c
BLAKE2b-256 6d66490dd76f4675ca1a5fb5937a64dab0948509005febc625025e511712c009

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page