@@ -12,120 +12,12 @@ An opinionated Python package that facilitates specifying AWS Lambda handlers.
12
12
13
13
It includes input validation, error handling and response formatting.
14
14
15
- ## Contents
15
+ ## Documentation
16
+ Read more about the project motivation and API documentation at:
16
17
17
- * [ Validators] ( validators.md )
18
- * [ API Reference] ( source/modules )
18
+ - [ https://lambda-handlers.readthedocs.io/en/latest/ ] ( https://lambda-handlers.readthedocs.io/en/latest/ )
19
19
20
- ## Getting started
21
-
22
- Install ` lambda-handlers ` with:
23
-
24
- ``` bash
25
- pip install lambda-handlers
26
- ```
27
-
28
- If you are going to use validation, you should choose between
29
- [ Marshmallow] ( https://pypi.org/project/marshmallow/ ) or
30
- [ jsonschema] ( https://pypi.org/project/jsonschema/ ) .
31
-
32
- To install with one of these:
33
-
34
- ``` bash
35
- pip install ' lambda-handlers[marshmallow]'
36
- ```
37
-
38
- or
39
-
40
- ``` bash
41
- pip install ' lambda-handlers[jsonschema]'
42
- ```
43
-
44
- ### Quickstart
45
-
46
- By default the ` http_handler ` decorator makes sure of parsing the request body
47
- as JSON, and also formats the response as JSON with:
48
-
49
- - an adequate statusCode,
50
- - CORS headers, and
51
- - the handler return value in the body.
52
-
53
- ``` python
54
- from lambda_handler import http_handler
55
-
56
- @http_handler ()
57
- def handler (event , context ):
58
- return event[' body' ]
59
- ```
60
-
61
- ### Examples
62
-
63
- Skipping the CORS headers default and configuring it.
64
-
65
- ``` python
66
- from lambda_handler import http_handler
67
- from lambda_handlers.response import cors
68
-
69
- @http_handler (
70
- cors = cors(origin = ' localhost' , credentials = False ),
71
- )
72
- def handler (event , context ):
73
- return event[' body' ]
74
- ```
75
-
76
- Using jsonschema to validate a the input of a User model.
77
-
78
- ``` python
79
- from typing import Dict, Any
80
-
81
- from lambda_handler import validators, http_handler
82
-
83
- user_schema: Dict[str , Any] = {
84
- ' type' : ' object' ,
85
- ' properties' : {
86
- ' user_id' : {' type' : ' number' },
87
- },
88
- }
89
-
90
-
91
- @http_handler (
92
- validator = validators.jsonschema(body = user_schema),
93
- )
94
- def handler (event , context ):
95
- user = event[' body' ]
96
- return user
97
- ```
98
-
99
- Using Marshmallow to validate a User model in the input and in
100
- the response body.
101
-
102
- ``` python
103
- from lambda_handler import validators, http_handler
104
- from marshmallow import Schema, fields
105
-
106
-
107
- class UserSchema (Schema ):
108
- user_id = fields.Integer(required = True )
109
-
110
-
111
- class ResponseSchema (Schema ):
112
- body = fields.Nested(UserSchema, required = True )
113
- headers = fields.Dict(required = True )
114
- statusCode = fields.Integer(required = True )
115
-
116
-
117
- @http_handler (
118
- validator = validators.marshmallow(
119
- body = UserSchema(),
120
- response = ResponseSchema(),
121
- ),
122
- )
123
- def handler (event , context ):
124
- user = event[' body' ]
125
- return user
126
- ```
127
-
128
- ## Using the source code
20
+ ## How to collaborate
129
21
130
22
This project uses [ pipenv] ( https://pipenv.readthedocs.io ) to manage its dependencies
131
23
and Python environment. You can install it by:
@@ -139,16 +31,6 @@ For that, we suggest using [pyenv](https://github.com/pyenv/pyenv-installer).
139
31
140
32
### Installation
141
33
142
- For production, after you clone this repository,
143
- you can install this project plus dependencies with:
144
-
145
- ``` bash
146
- cd < clone_dest>
147
- make install
148
- ```
149
-
150
- ### Development
151
-
152
34
For development you should also install the development dependencies,
153
35
so run instead:
154
36
0 commit comments