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. And only supports python3

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.1a1.tar.gz (3.9 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.1a1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for lambda-decorators-0.1a1.tar.gz
Algorithm Hash digest
SHA256 d9e595df74ee5ff4b6284ea936f1b76bfa80f7d617a9c40fcec50787fdfcdd01
MD5 418110d8304d48ae5d943b991edc5e6e
BLAKE2b-256 aab05acbfe71f2e7a6a585b59f48a515c59d2d346c1d23a1d48c6c810febdc06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lambda_decorators-0.1a1-py3-none-any.whl
Algorithm Hash digest
SHA256 78bbbc92050fe200dc32de622458d9769f6341e7fbb6d9cba0ff4129444bbb60
MD5 319087215f934bd36f32a3aa2661d861
BLAKE2b-256 8e9476a0e334a219118b6656acc49c8468674ffbbb24d1d485ad26e56980d22e

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