lambda-api-decorators 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lambda_api_decorators/__init__.py +1 -0
- lambda_api_decorators/decorators.py +119 -0
- lambda_api_decorators-0.1.0.dist-info/METADATA +233 -0
- lambda_api_decorators-0.1.0.dist-info/RECORD +7 -0
- lambda_api_decorators-0.1.0.dist-info/WHEEL +5 -0
- lambda_api_decorators-0.1.0.dist-info/licenses/LICENSE +21 -0
- lambda_api_decorators-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .decorators import *
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
def GET(path):
|
|
2
|
+
def decorator(fun):
|
|
3
|
+
def wrapper(*args, **kwargs):
|
|
4
|
+
result = fun(*args, **kwargs)
|
|
5
|
+
return result
|
|
6
|
+
return wrapper
|
|
7
|
+
return decorator
|
|
8
|
+
|
|
9
|
+
def PUT(path):
|
|
10
|
+
def decorator(fun):
|
|
11
|
+
def wrapper(*args, **kwargs):
|
|
12
|
+
result = fun(*args, **kwargs)
|
|
13
|
+
return result
|
|
14
|
+
return wrapper
|
|
15
|
+
return decorator
|
|
16
|
+
|
|
17
|
+
def POST(path):
|
|
18
|
+
def decorator(fun):
|
|
19
|
+
def wrapper(*args, **kwargs):
|
|
20
|
+
result = fun(*args, **kwargs)
|
|
21
|
+
return result
|
|
22
|
+
return wrapper
|
|
23
|
+
return decorator
|
|
24
|
+
|
|
25
|
+
def DELETE(path):
|
|
26
|
+
def decorator(fun):
|
|
27
|
+
def wrapper(*args, **kwargs):
|
|
28
|
+
result = fun(*args, **kwargs)
|
|
29
|
+
return result
|
|
30
|
+
return wrapper
|
|
31
|
+
return decorator
|
|
32
|
+
|
|
33
|
+
def ANY(path):
|
|
34
|
+
def decorator(fun):
|
|
35
|
+
def wrapper(*args, **kwargs):
|
|
36
|
+
result = fun(*args, **kwargs)
|
|
37
|
+
return result
|
|
38
|
+
return wrapper
|
|
39
|
+
return decorator
|
|
40
|
+
|
|
41
|
+
def memory_size(arg):
|
|
42
|
+
def decorator(fun):
|
|
43
|
+
def wrapper(*args, **kwargs):
|
|
44
|
+
result = fun(*args, **kwargs)
|
|
45
|
+
return result
|
|
46
|
+
return wrapper
|
|
47
|
+
return decorator
|
|
48
|
+
|
|
49
|
+
def timeout(arg):
|
|
50
|
+
def decorator(fun):
|
|
51
|
+
def wrapper(*args, **kwargs):
|
|
52
|
+
result = fun(*args, **kwargs)
|
|
53
|
+
return result
|
|
54
|
+
return wrapper
|
|
55
|
+
return decorator
|
|
56
|
+
|
|
57
|
+
def environment(*eargs, **kwargs):
|
|
58
|
+
def decorator(fun):
|
|
59
|
+
def wrapper(*args, **kwargs):
|
|
60
|
+
result = fun(*args, **kwargs)
|
|
61
|
+
return result
|
|
62
|
+
return wrapper
|
|
63
|
+
return decorator
|
|
64
|
+
|
|
65
|
+
def layer(*largs, **kwargs):
|
|
66
|
+
def decorator(fun):
|
|
67
|
+
def wrapper(*args, **kwargs):
|
|
68
|
+
result = fun(*args, **kwargs)
|
|
69
|
+
return result
|
|
70
|
+
return wrapper
|
|
71
|
+
return decorator
|
|
72
|
+
|
|
73
|
+
def runtime(arg):
|
|
74
|
+
def decorator(fun):
|
|
75
|
+
def wrapper(*args, **kwargs):
|
|
76
|
+
result = fun(*args, **kwargs)
|
|
77
|
+
return result
|
|
78
|
+
return wrapper
|
|
79
|
+
return decorator
|
|
80
|
+
|
|
81
|
+
def security_group(*sgargs):
|
|
82
|
+
def decorator(fun):
|
|
83
|
+
def wrapper(*wargs, **kwargs):
|
|
84
|
+
result = fun(*wargs, **kwargs)
|
|
85
|
+
return result
|
|
86
|
+
return wrapper
|
|
87
|
+
return decorator
|
|
88
|
+
|
|
89
|
+
def vpc(arg):
|
|
90
|
+
def decorator(fun):
|
|
91
|
+
def wrapper(*args, **kwargs):
|
|
92
|
+
result = fun(*args, **kwargs)
|
|
93
|
+
return result
|
|
94
|
+
return wrapper
|
|
95
|
+
return decorator
|
|
96
|
+
|
|
97
|
+
def role(arg):
|
|
98
|
+
def decorator(fun):
|
|
99
|
+
def wrapper(*args, **kwargs):
|
|
100
|
+
result = fun(*args, **kwargs)
|
|
101
|
+
return result
|
|
102
|
+
return wrapper
|
|
103
|
+
return decorator
|
|
104
|
+
|
|
105
|
+
def description(arg):
|
|
106
|
+
def decorator(fun):
|
|
107
|
+
def wrapper(*args, **kwargs):
|
|
108
|
+
result = fun(*args, **kwargs)
|
|
109
|
+
return result
|
|
110
|
+
return wrapper
|
|
111
|
+
return decorator
|
|
112
|
+
|
|
113
|
+
def name(arg):
|
|
114
|
+
def decorator(fun):
|
|
115
|
+
def wrapper(*args, **kwargs):
|
|
116
|
+
result = fun(*args, **kwargs)
|
|
117
|
+
return result
|
|
118
|
+
return wrapper
|
|
119
|
+
return decorator
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lambda-api-decorators
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python decorators for defining AWS Lambda API routes and configuration.
|
|
5
|
+
Author: Mateo Marcos, Emanuel Arguinarena, Lucas Picchi
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Lambda API Decorators
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/lambda-api-decorators/lambda-api-decorators
|
|
29
|
+
Project-URL: Repository, https://github.com/lambda-api-decorators/lambda-api-decorators
|
|
30
|
+
Project-URL: Bug Reports, https://github.com/lambda-api-decorators/lambda-api-decorators/issues
|
|
31
|
+
Keywords: cdk,lambda,aws,api gateway,ast,decorators
|
|
32
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
33
|
+
Classifier: Intended Audience :: Developers
|
|
34
|
+
Classifier: Framework :: AWS CDK :: 2
|
|
35
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
36
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
37
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
42
|
+
Requires-Python: >=3.9
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
License-File: LICENSE
|
|
45
|
+
Dynamic: license-file
|
|
46
|
+
|
|
47
|
+
# Lambda API Decorators
|
|
48
|
+
|
|
49
|
+
**Define AWS Lambda API routes and configuration directly in your Python code using decorators.**
|
|
50
|
+
|
|
51
|
+
Lambda API Decorators provides Python decorators for defining API routes and AWS Lambda configuration alongside your Lambda handlers.
|
|
52
|
+
|
|
53
|
+
Instead of maintaining route and function configuration separately from your application code, you can declare HTTP methods, paths, runtimes, timeouts, memory, environment variables, layers, networking, and other Lambda settings directly on the handler.
|
|
54
|
+
|
|
55
|
+
Combined with **Lambda API Decorators CDK**, these definitions are used to automatically generate the corresponding AWS Lambda and Amazon API Gateway infrastructure with AWS CDK.
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from lambda_api_decorators import GET, runtime, name, memory_size
|
|
59
|
+
import json
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@GET("/dogs")
|
|
63
|
+
@runtime("python3.11")
|
|
64
|
+
@name("LBD-DOGS-GET")
|
|
65
|
+
@memory_size(256)
|
|
66
|
+
def lambda_handler(event, context):
|
|
67
|
+
return {
|
|
68
|
+
"statusCode": 200,
|
|
69
|
+
"body": json.dumps({
|
|
70
|
+
"message": "Hello World from /dogs!"
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Installation
|
|
76
|
+
|
|
77
|
+
Install Lambda API Decorators from PyPI:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install lambda-api-decorators
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
To generate AWS infrastructure from the decorated Lambda handlers, install the CDK integration:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pip install lambda-api-decorators-cdk
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Available Decorators
|
|
90
|
+
|
|
91
|
+
### API Routes
|
|
92
|
+
|
|
93
|
+
Every Lambda API handler must define an HTTP method and endpoint path.
|
|
94
|
+
|
|
95
|
+
Available route decorators:
|
|
96
|
+
|
|
97
|
+
* `GET`
|
|
98
|
+
* `POST`
|
|
99
|
+
* `PUT`
|
|
100
|
+
* `DELETE`
|
|
101
|
+
* `ANY`
|
|
102
|
+
|
|
103
|
+
For example:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
@GET("/dogs")
|
|
107
|
+
def lambda_handler(event, context):
|
|
108
|
+
...
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The route definition is used by the CDK integration to configure the corresponding Amazon API Gateway endpoint and Lambda integration.
|
|
112
|
+
|
|
113
|
+
### Lambda Configuration
|
|
114
|
+
|
|
115
|
+
Lambda API Decorators also allows Lambda configuration to be declared directly on the handler.
|
|
116
|
+
|
|
117
|
+
#### `timeout`
|
|
118
|
+
|
|
119
|
+
Defines the Lambda function timeout in seconds.
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
@timeout(30)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### `memory_size`
|
|
126
|
+
|
|
127
|
+
Defines the amount of memory allocated to the Lambda function.
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
@memory_size(512)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### `name`
|
|
134
|
+
|
|
135
|
+
Defines a custom name for the Lambda function.
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
@name("LBD-DOGS-GET")
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### `description`
|
|
142
|
+
|
|
143
|
+
Defines the Lambda function description.
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
@description("Returns the list of dogs")
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
#### `runtime`
|
|
150
|
+
|
|
151
|
+
References a runtime configuration defined by Lambda API Decorators CDK.
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
@runtime("python3.11")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### `role`
|
|
158
|
+
|
|
159
|
+
References an IAM role defined by Lambda API Decorators CDK.
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
@role("api-role")
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
#### `vpc`
|
|
166
|
+
|
|
167
|
+
References a VPC configuration defined by Lambda API Decorators CDK.
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
@vpc("application-vpc")
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
#### `environment`
|
|
174
|
+
|
|
175
|
+
Associates one or more environment configurations with the Lambda function.
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
@environment("database", "application")
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### `layer`
|
|
182
|
+
|
|
183
|
+
Associates one or more Lambda Layers with the function.
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
@layer("common-dependencies")
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
#### `security_group`
|
|
190
|
+
|
|
191
|
+
Associates one or more security group configurations with the Lambda function.
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
@security_group("lambda-security-group")
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
The referenced runtimes, IAM roles, VPCs, environment configurations, layers, and security groups are defined in the AWS CDK application using **Lambda API Decorators CDK**.
|
|
198
|
+
|
|
199
|
+
## How It Works
|
|
200
|
+
|
|
201
|
+
Lambda API Decorators keeps API and Lambda configuration close to the application code:
|
|
202
|
+
|
|
203
|
+
```text
|
|
204
|
+
Python Lambda handlers
|
|
205
|
+
│
|
|
206
|
+
│ @GET, @POST, @runtime,
|
|
207
|
+
│ @timeout, @memory_size, ...
|
|
208
|
+
▼
|
|
209
|
+
Lambda API Decorators
|
|
210
|
+
│
|
|
211
|
+
▼
|
|
212
|
+
Lambda API Decorators CDK
|
|
213
|
+
│
|
|
214
|
+
▼
|
|
215
|
+
AWS CDK
|
|
216
|
+
│
|
|
217
|
+
├── AWS Lambda
|
|
218
|
+
├── Amazon API Gateway
|
|
219
|
+
├── IAM
|
|
220
|
+
├── VPC configuration
|
|
221
|
+
└── other AWS resources
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
This allows your Lambda handlers to become the source of the API definition while AWS CDK remains responsible for generating and deploying the infrastructure.
|
|
225
|
+
|
|
226
|
+
## Related Projects
|
|
227
|
+
|
|
228
|
+
* **Lambda API Decorators CDK** — AWS CDK integration that generates Lambda and API Gateway infrastructure from decorated Python handlers.
|
|
229
|
+
* **Lambda API Decorators Examples** — Example applications demonstrating how to use Lambda API Decorators.
|
|
230
|
+
|
|
231
|
+
## License
|
|
232
|
+
|
|
233
|
+
See the repository license for details.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
lambda_api_decorators/__init__.py,sha256=FXs_TA9H6e1iMspQ-HFtVFv59q9Bfw0k5HpxhgLovJM,26
|
|
2
|
+
lambda_api_decorators/decorators.py,sha256=FGS3c5AiPEB9BmdVg6Rv_xObbhbkNK2YAljDMljjeBg,2939
|
|
3
|
+
lambda_api_decorators-0.1.0.dist-info/licenses/LICENSE,sha256=E9RhjRL38P23iXHzNiN9s4KK0_xto3eUu-V-qJ5uJXM,1078
|
|
4
|
+
lambda_api_decorators-0.1.0.dist-info/METADATA,sha256=OMRqke5HGp-W_rPIfqlTwajmwf5k4PSupPbotmRf7oc,6616
|
|
5
|
+
lambda_api_decorators-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
6
|
+
lambda_api_decorators-0.1.0.dist-info/top_level.txt,sha256=gfwH7c72QGh98BsLEexv-enLG5dLboIZjA0fSGY2TZE,22
|
|
7
|
+
lambda_api_decorators-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Lambda API Decorators
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lambda_api_decorators
|