A collection of useful decorators for making AWS Lambda handlers
Project description
🐍λ✨ - lambda_decorators
=========================
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 <https://aws.amazon.com/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
-------------
.. code:: python
# 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:
.. code:: shell
$ curl -d '{"name": "world"}' https://example.execute-api.us-east-1.amazonaws.com/dev/hello
{"hello": "world"}
Install
-------
.. code:: shell
pip install lambda-decorators
Why
---
Initially, I was inspired by `middy <https://github.com/middyjs/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 <https://wiki.python.org/moin/PythonDecorators>`_
pretty much are middleware! So instead of
building a middleware engine and a few middlewares, I just built a few
useful decorators.
Included Decorators:
--------------------
* :meth:`async_handler` - support for async handlers
* :meth:`cors_headers` - automatic injection of CORS headers
* :meth:`dump_json_body` - auto-serialization of http body to JSON
* :meth:`json_http_resp` - automatic serialization of python object to HTTP JSON response
* :meth:`load_json_body` - auto-deserialize of http body from JSON
* :meth:`no_retry_on_failure` - detect and stop retry attempts for scheduled lambdas
See each individual decorators for specific usage details and the example_
for some more use cases.
.. _example: https://github.com/dschep/lambda-decorators/tree/master/example
-----
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lambda-decorators-0.1a3.tar.gz.
File metadata
- Download URL: lambda-decorators-0.1a3.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb5c3683b4aac9c280333effd4e3d2c0fe94b899f1a67f376da07d63f7bd4857
|
|
| MD5 |
fcd16d4ebf6fcda946c80a46e753acd6
|
|
| BLAKE2b-256 |
2a30bf248dc8e9881c6a17cdf0afe24f8ae8c48826c52f6df445378921dca1ec
|
File details
Details for the file lambda_decorators-0.1a3-py3-none-any.whl.
File metadata
- Download URL: lambda_decorators-0.1a3-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e36923fa329b95f2ea281e8409518405a1d6e5d0afff08f3ae40e6b488d1107
|
|
| MD5 |
76f8953e2e042f4ac162cc89039d66e0
|
|
| BLAKE2b-256 |
755d9374409ffe12a99d62942d414b3e7ec9030e1e617b536190e6e6b65c4f37
|