lambda-api-decorators-cdk 0.4.0__tar.gz → 0.4.1__tar.gz
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_cdk-0.4.1/PKG-INFO +196 -0
- lambda_api_decorators_cdk-0.4.1/README.md +149 -0
- lambda_api_decorators_cdk-0.4.1/src/lambda_api_decorators_cdk.egg-info/PKG-INFO +196 -0
- lambda_api_decorators_cdk-0.4.1/src/lambda_api_decorators_cdk.egg-info/scm_version.json +8 -0
- lambda_api_decorators_cdk-0.4.0/PKG-INFO +0 -145
- lambda_api_decorators_cdk-0.4.0/README.md +0 -98
- lambda_api_decorators_cdk-0.4.0/src/lambda_api_decorators_cdk.egg-info/PKG-INFO +0 -145
- lambda_api_decorators_cdk-0.4.0/src/lambda_api_decorators_cdk.egg-info/scm_version.json +0 -8
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/.github/workflows/release.yml +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/.github/workflows/tests.yml +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/.gitignore +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/AGENTS.md +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/LICENSE +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/pyproject.toml +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/setup.cfg +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/src/lambda_api_decorators_cdk/__init__.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/src/lambda_api_decorators_cdk/api_type.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/src/lambda_api_decorators_cdk/ast_helper.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/src/lambda_api_decorators_cdk/lambda_api.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/src/lambda_api_decorators_cdk/lambda_api_config.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/src/lambda_api_decorators_cdk/resource_builder.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/src/lambda_api_decorators_cdk/source_layout.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/src/lambda_api_decorators_cdk.egg-info/SOURCES.txt +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/src/lambda_api_decorators_cdk.egg-info/dependency_links.txt +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/src/lambda_api_decorators_cdk.egg-info/requires.txt +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/src/lambda_api_decorators_cdk.egg-info/scm_file_list.json +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/src/lambda_api_decorators_cdk.egg-info/top_level.txt +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/conftest.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_ast_decorator_invocations.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_ast_helper.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_auth_ast.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_authorization_diagnostics.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_authorization_http.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_authorization_lambda_api.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_authorization_resolution.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_authorization_rest.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_authorizer_config.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_http_builder.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_lambda_api.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_lambda_api_config.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_lambda_function.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_layer_autodiscovery.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_packaging_current.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_permission_resolution.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_public_api.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_python_compatibility.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_resource_builder_options.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_resource_builder_state.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_resource_graph.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_resource_registries.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_rest_builder.py +0 -0
- {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_source_layout.py +0 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lambda-api-decorators-cdk
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: AWS CDK integration for Lambda API Decorators. Generate AWS Lambda and API Gateway infrastructure from decorated Python handlers.
|
|
5
|
+
Author: Mateo Marcos, Emanuel Arguinarena, Lucas Picchi
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Lambda API Decorators CDK
|
|
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
|
+
Project-URL: Homepage, https://github.com/lambda-api-decorators/lambda-api-decorators-cdk
|
|
28
|
+
Project-URL: Repository, https://github.com/lambda-api-decorators/lambda-api-decorators-cdk
|
|
29
|
+
Project-URL: Bug Reports, https://github.com/lambda-api-decorators/lambda-api-decorators-cdk
|
|
30
|
+
Keywords: cdk,lambda,aws,api gateway,ast
|
|
31
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: Framework :: AWS CDK :: 2
|
|
34
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
35
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
42
|
+
Requires-Python: >=3.10
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
License-File: LICENSE
|
|
45
|
+
Requires-Dist: aws-cdk.aws-lambda-python-alpha
|
|
46
|
+
Dynamic: license-file
|
|
47
|
+
|
|
48
|
+
# Lambda API Decorators CDK
|
|
49
|
+
|
|
50
|
+
AWS CDK integration for [Lambda API Decorators](https://github.com/infrastructure-as-decorator/lambda-api-decorators). Define API routes with Python decorators and let CDK create the Lambda functions, integrations, routes, and related configuration.
|
|
51
|
+
|
|
52
|
+
The complete cross-package guides and architecture documentation are available at [lambda-api-decorators.github.io](https://infrastructure-as-decorator.github.io/).
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install lambda-api-decorators-cdk
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The package requires Python 3.10 or newer and AWS CDK v2. The `lambda-api-decorators` package provides the decorators used by the Lambda source files.
|
|
61
|
+
|
|
62
|
+
## Quick start
|
|
63
|
+
|
|
64
|
+
`LambdaApi` is the recommended high-level construct. It creates a REST API by default and discovers decorated handlers below `lambda_path`.
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from aws_cdk import Stack
|
|
68
|
+
from constructs import Construct
|
|
69
|
+
|
|
70
|
+
from lambda_api_decorators_cdk import LambdaApi
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class ExampleStack(Stack):
|
|
74
|
+
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
|
|
75
|
+
super().__init__(scope, construct_id, **kwargs)
|
|
76
|
+
|
|
77
|
+
LambdaApi(self, "ExampleApi", lambda_path="lambdas")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
A handler must include an HTTP method decorator from `lambda-api-decorators`:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from lambda_api_decorators import GET
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@GET("/hello")
|
|
87
|
+
def hello(event, context):
|
|
88
|
+
return {"statusCode": 200, "body": "Hello, world!"}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`lambda_path` is resolved from the directory where CDK is run. Files without a supported route decorator are ignored.
|
|
92
|
+
|
|
93
|
+
## API types and imported APIs
|
|
94
|
+
|
|
95
|
+
REST is the default. Select an HTTP API with `ApiType.HTTP`, or provide an existing supported API and let the construct infer its type.
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from aws_cdk import aws_apigateway as apigateway
|
|
99
|
+
from lambda_api_decorators_cdk import ApiType, LambdaApi
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
LambdaApi(self, "HttpApi", lambda_path="lambdas", api_type=ApiType.HTTP)
|
|
103
|
+
|
|
104
|
+
existing_rest_api = apigateway.RestApi(self, "ExistingRestApi")
|
|
105
|
+
LambdaApi(self, "ExistingApiRoutes", lambda_path="lambdas", api=existing_rest_api)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Created and imported REST APIs are supported. Concrete `aws_apigatewayv2.HttpApi` instances are supported for HTTP APIs.
|
|
109
|
+
|
|
110
|
+
## Reusable configuration
|
|
111
|
+
|
|
112
|
+
Use `LambdaApiConfig` for defaults and named resources shared by one or more `LambdaApi` constructs. Configuration must be complete before constructing the API.
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from aws_cdk import Duration, aws_lambda as lambda_
|
|
116
|
+
from lambda_api_decorators_cdk import LambdaApi, LambdaApiConfig
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
config = LambdaApiConfig(
|
|
120
|
+
runtime=lambda_.Runtime.PYTHON_3_12,
|
|
121
|
+
timeout=Duration.seconds(30),
|
|
122
|
+
memory_size=512,
|
|
123
|
+
environment={"ENVIRONMENT": "production"},
|
|
124
|
+
)
|
|
125
|
+
config.add_custom_environment("PAYMENTS_URL", "https://payments.example.com")
|
|
126
|
+
|
|
127
|
+
LambdaApi(self, "ConfiguredApi", lambda_path="lambdas", config=config)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`LambdaApiConfig` supports default and custom runtimes, roles, VPCs, subnets, layers, security groups, and environment variables. It also supports registries for DynamoDB tables, S3 buckets, and REST or HTTP authorizers. A reused configuration creates an isolated builder snapshot for each API.
|
|
131
|
+
|
|
132
|
+
## Source layout and layers
|
|
133
|
+
|
|
134
|
+
By default, each handler is packaged relative to the source root. For a service-oriented layout, use `SourceLayout.SERVICE`:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from lambda_api_decorators_cdk import LambdaApi, SourceLayout
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
LambdaApi(
|
|
141
|
+
self,
|
|
142
|
+
"ServiceApi",
|
|
143
|
+
lambda_path="services",
|
|
144
|
+
source_layout=SourceLayout.SERVICE,
|
|
145
|
+
layers_path="layers",
|
|
146
|
+
)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
When `layers_path` is provided, each visible child directory is treated as a discoverable layer source. Explicit layer configuration remains available through `LambdaApiConfig`.
|
|
150
|
+
|
|
151
|
+
## Authorization and permissions
|
|
152
|
+
|
|
153
|
+
Register authorizers with a logical key and select the default authorizer for routes. A handler can override the default with `@authorizer("key")` or make itself public with `@public`.
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
from aws_cdk import aws_apigateway as apigateway
|
|
157
|
+
from lambda_api_decorators_cdk import LambdaApiConfig
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
authorizer = apigateway.TokenAuthorizer(self, "UsersAuthorizer", handler=authorizer_fn)
|
|
161
|
+
config = LambdaApiConfig(authorizers={"users": authorizer}, default_authorizer="users")
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The resource registries also allow decorated handlers to request least-privilege grants for registered DynamoDB tables and S3 buckets. See the [complete documentation](https://lambda-api-decorators.github.io/) for decorator syntax and supported access levels.
|
|
165
|
+
|
|
166
|
+
## Low-level builder
|
|
167
|
+
|
|
168
|
+
`ResourceBuilder` remains a supported lower-level API for callers that need direct control over the API root or build lifecycle:
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
from aws_cdk import Duration
|
|
172
|
+
from lambda_api_decorators_cdk import ResourceBuilder
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
builder = ResourceBuilder()
|
|
176
|
+
builder.set_default_timeout(Duration.seconds(30))
|
|
177
|
+
builder.add_common_environment("ENVIRONMENT", "production")
|
|
178
|
+
builder.build(self, rest_api.root, "lambdas")
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Prefer `LambdaApi` for new code. It owns API creation or reuse and delegates option resolution to isolated `ResourceBuilder` snapshots.
|
|
182
|
+
|
|
183
|
+
## Releases
|
|
184
|
+
|
|
185
|
+
The Git tag is the single source of truth for this package's version. For example, `v0.3.0` produces Python package version `0.3.0`. This repository is versioned independently from `lambda-api-decorators`.
|
|
186
|
+
|
|
187
|
+
To release from `main`, push a semantic version tag:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
git checkout main
|
|
191
|
+
git pull
|
|
192
|
+
git tag v0.3.0
|
|
193
|
+
git push origin v0.3.0
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Pushing the tag triggers the release workflow, which tests, builds, verifies the version, and publishes to PyPI using trusted publishing. The PyPI project must have a trusted publisher configured for this repository, the `release.yml` workflow, and the `pypi` GitHub environment.
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Lambda API Decorators CDK
|
|
2
|
+
|
|
3
|
+
AWS CDK integration for [Lambda API Decorators](https://github.com/infrastructure-as-decorator/lambda-api-decorators). Define API routes with Python decorators and let CDK create the Lambda functions, integrations, routes, and related configuration.
|
|
4
|
+
|
|
5
|
+
The complete cross-package guides and architecture documentation are available at [lambda-api-decorators.github.io](https://infrastructure-as-decorator.github.io/).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install lambda-api-decorators-cdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The package requires Python 3.10 or newer and AWS CDK v2. The `lambda-api-decorators` package provides the decorators used by the Lambda source files.
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
`LambdaApi` is the recommended high-level construct. It creates a REST API by default and discovers decorated handlers below `lambda_path`.
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from aws_cdk import Stack
|
|
21
|
+
from constructs import Construct
|
|
22
|
+
|
|
23
|
+
from lambda_api_decorators_cdk import LambdaApi
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ExampleStack(Stack):
|
|
27
|
+
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
|
|
28
|
+
super().__init__(scope, construct_id, **kwargs)
|
|
29
|
+
|
|
30
|
+
LambdaApi(self, "ExampleApi", lambda_path="lambdas")
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
A handler must include an HTTP method decorator from `lambda-api-decorators`:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from lambda_api_decorators import GET
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@GET("/hello")
|
|
40
|
+
def hello(event, context):
|
|
41
|
+
return {"statusCode": 200, "body": "Hello, world!"}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`lambda_path` is resolved from the directory where CDK is run. Files without a supported route decorator are ignored.
|
|
45
|
+
|
|
46
|
+
## API types and imported APIs
|
|
47
|
+
|
|
48
|
+
REST is the default. Select an HTTP API with `ApiType.HTTP`, or provide an existing supported API and let the construct infer its type.
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from aws_cdk import aws_apigateway as apigateway
|
|
52
|
+
from lambda_api_decorators_cdk import ApiType, LambdaApi
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
LambdaApi(self, "HttpApi", lambda_path="lambdas", api_type=ApiType.HTTP)
|
|
56
|
+
|
|
57
|
+
existing_rest_api = apigateway.RestApi(self, "ExistingRestApi")
|
|
58
|
+
LambdaApi(self, "ExistingApiRoutes", lambda_path="lambdas", api=existing_rest_api)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Created and imported REST APIs are supported. Concrete `aws_apigatewayv2.HttpApi` instances are supported for HTTP APIs.
|
|
62
|
+
|
|
63
|
+
## Reusable configuration
|
|
64
|
+
|
|
65
|
+
Use `LambdaApiConfig` for defaults and named resources shared by one or more `LambdaApi` constructs. Configuration must be complete before constructing the API.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from aws_cdk import Duration, aws_lambda as lambda_
|
|
69
|
+
from lambda_api_decorators_cdk import LambdaApi, LambdaApiConfig
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
config = LambdaApiConfig(
|
|
73
|
+
runtime=lambda_.Runtime.PYTHON_3_12,
|
|
74
|
+
timeout=Duration.seconds(30),
|
|
75
|
+
memory_size=512,
|
|
76
|
+
environment={"ENVIRONMENT": "production"},
|
|
77
|
+
)
|
|
78
|
+
config.add_custom_environment("PAYMENTS_URL", "https://payments.example.com")
|
|
79
|
+
|
|
80
|
+
LambdaApi(self, "ConfiguredApi", lambda_path="lambdas", config=config)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`LambdaApiConfig` supports default and custom runtimes, roles, VPCs, subnets, layers, security groups, and environment variables. It also supports registries for DynamoDB tables, S3 buckets, and REST or HTTP authorizers. A reused configuration creates an isolated builder snapshot for each API.
|
|
84
|
+
|
|
85
|
+
## Source layout and layers
|
|
86
|
+
|
|
87
|
+
By default, each handler is packaged relative to the source root. For a service-oriented layout, use `SourceLayout.SERVICE`:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from lambda_api_decorators_cdk import LambdaApi, SourceLayout
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
LambdaApi(
|
|
94
|
+
self,
|
|
95
|
+
"ServiceApi",
|
|
96
|
+
lambda_path="services",
|
|
97
|
+
source_layout=SourceLayout.SERVICE,
|
|
98
|
+
layers_path="layers",
|
|
99
|
+
)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
When `layers_path` is provided, each visible child directory is treated as a discoverable layer source. Explicit layer configuration remains available through `LambdaApiConfig`.
|
|
103
|
+
|
|
104
|
+
## Authorization and permissions
|
|
105
|
+
|
|
106
|
+
Register authorizers with a logical key and select the default authorizer for routes. A handler can override the default with `@authorizer("key")` or make itself public with `@public`.
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from aws_cdk import aws_apigateway as apigateway
|
|
110
|
+
from lambda_api_decorators_cdk import LambdaApiConfig
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
authorizer = apigateway.TokenAuthorizer(self, "UsersAuthorizer", handler=authorizer_fn)
|
|
114
|
+
config = LambdaApiConfig(authorizers={"users": authorizer}, default_authorizer="users")
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The resource registries also allow decorated handlers to request least-privilege grants for registered DynamoDB tables and S3 buckets. See the [complete documentation](https://lambda-api-decorators.github.io/) for decorator syntax and supported access levels.
|
|
118
|
+
|
|
119
|
+
## Low-level builder
|
|
120
|
+
|
|
121
|
+
`ResourceBuilder` remains a supported lower-level API for callers that need direct control over the API root or build lifecycle:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from aws_cdk import Duration
|
|
125
|
+
from lambda_api_decorators_cdk import ResourceBuilder
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
builder = ResourceBuilder()
|
|
129
|
+
builder.set_default_timeout(Duration.seconds(30))
|
|
130
|
+
builder.add_common_environment("ENVIRONMENT", "production")
|
|
131
|
+
builder.build(self, rest_api.root, "lambdas")
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Prefer `LambdaApi` for new code. It owns API creation or reuse and delegates option resolution to isolated `ResourceBuilder` snapshots.
|
|
135
|
+
|
|
136
|
+
## Releases
|
|
137
|
+
|
|
138
|
+
The Git tag is the single source of truth for this package's version. For example, `v0.3.0` produces Python package version `0.3.0`. This repository is versioned independently from `lambda-api-decorators`.
|
|
139
|
+
|
|
140
|
+
To release from `main`, push a semantic version tag:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
git checkout main
|
|
144
|
+
git pull
|
|
145
|
+
git tag v0.3.0
|
|
146
|
+
git push origin v0.3.0
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Pushing the tag triggers the release workflow, which tests, builds, verifies the version, and publishes to PyPI using trusted publishing. The PyPI project must have a trusted publisher configured for this repository, the `release.yml` workflow, and the `pypi` GitHub environment.
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lambda-api-decorators-cdk
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: AWS CDK integration for Lambda API Decorators. Generate AWS Lambda and API Gateway infrastructure from decorated Python handlers.
|
|
5
|
+
Author: Mateo Marcos, Emanuel Arguinarena, Lucas Picchi
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Lambda API Decorators CDK
|
|
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
|
+
Project-URL: Homepage, https://github.com/lambda-api-decorators/lambda-api-decorators-cdk
|
|
28
|
+
Project-URL: Repository, https://github.com/lambda-api-decorators/lambda-api-decorators-cdk
|
|
29
|
+
Project-URL: Bug Reports, https://github.com/lambda-api-decorators/lambda-api-decorators-cdk
|
|
30
|
+
Keywords: cdk,lambda,aws,api gateway,ast
|
|
31
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: Framework :: AWS CDK :: 2
|
|
34
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
35
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
42
|
+
Requires-Python: >=3.10
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
License-File: LICENSE
|
|
45
|
+
Requires-Dist: aws-cdk.aws-lambda-python-alpha
|
|
46
|
+
Dynamic: license-file
|
|
47
|
+
|
|
48
|
+
# Lambda API Decorators CDK
|
|
49
|
+
|
|
50
|
+
AWS CDK integration for [Lambda API Decorators](https://github.com/infrastructure-as-decorator/lambda-api-decorators). Define API routes with Python decorators and let CDK create the Lambda functions, integrations, routes, and related configuration.
|
|
51
|
+
|
|
52
|
+
The complete cross-package guides and architecture documentation are available at [lambda-api-decorators.github.io](https://infrastructure-as-decorator.github.io/).
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install lambda-api-decorators-cdk
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The package requires Python 3.10 or newer and AWS CDK v2. The `lambda-api-decorators` package provides the decorators used by the Lambda source files.
|
|
61
|
+
|
|
62
|
+
## Quick start
|
|
63
|
+
|
|
64
|
+
`LambdaApi` is the recommended high-level construct. It creates a REST API by default and discovers decorated handlers below `lambda_path`.
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from aws_cdk import Stack
|
|
68
|
+
from constructs import Construct
|
|
69
|
+
|
|
70
|
+
from lambda_api_decorators_cdk import LambdaApi
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class ExampleStack(Stack):
|
|
74
|
+
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
|
|
75
|
+
super().__init__(scope, construct_id, **kwargs)
|
|
76
|
+
|
|
77
|
+
LambdaApi(self, "ExampleApi", lambda_path="lambdas")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
A handler must include an HTTP method decorator from `lambda-api-decorators`:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from lambda_api_decorators import GET
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@GET("/hello")
|
|
87
|
+
def hello(event, context):
|
|
88
|
+
return {"statusCode": 200, "body": "Hello, world!"}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`lambda_path` is resolved from the directory where CDK is run. Files without a supported route decorator are ignored.
|
|
92
|
+
|
|
93
|
+
## API types and imported APIs
|
|
94
|
+
|
|
95
|
+
REST is the default. Select an HTTP API with `ApiType.HTTP`, or provide an existing supported API and let the construct infer its type.
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from aws_cdk import aws_apigateway as apigateway
|
|
99
|
+
from lambda_api_decorators_cdk import ApiType, LambdaApi
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
LambdaApi(self, "HttpApi", lambda_path="lambdas", api_type=ApiType.HTTP)
|
|
103
|
+
|
|
104
|
+
existing_rest_api = apigateway.RestApi(self, "ExistingRestApi")
|
|
105
|
+
LambdaApi(self, "ExistingApiRoutes", lambda_path="lambdas", api=existing_rest_api)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Created and imported REST APIs are supported. Concrete `aws_apigatewayv2.HttpApi` instances are supported for HTTP APIs.
|
|
109
|
+
|
|
110
|
+
## Reusable configuration
|
|
111
|
+
|
|
112
|
+
Use `LambdaApiConfig` for defaults and named resources shared by one or more `LambdaApi` constructs. Configuration must be complete before constructing the API.
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from aws_cdk import Duration, aws_lambda as lambda_
|
|
116
|
+
from lambda_api_decorators_cdk import LambdaApi, LambdaApiConfig
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
config = LambdaApiConfig(
|
|
120
|
+
runtime=lambda_.Runtime.PYTHON_3_12,
|
|
121
|
+
timeout=Duration.seconds(30),
|
|
122
|
+
memory_size=512,
|
|
123
|
+
environment={"ENVIRONMENT": "production"},
|
|
124
|
+
)
|
|
125
|
+
config.add_custom_environment("PAYMENTS_URL", "https://payments.example.com")
|
|
126
|
+
|
|
127
|
+
LambdaApi(self, "ConfiguredApi", lambda_path="lambdas", config=config)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`LambdaApiConfig` supports default and custom runtimes, roles, VPCs, subnets, layers, security groups, and environment variables. It also supports registries for DynamoDB tables, S3 buckets, and REST or HTTP authorizers. A reused configuration creates an isolated builder snapshot for each API.
|
|
131
|
+
|
|
132
|
+
## Source layout and layers
|
|
133
|
+
|
|
134
|
+
By default, each handler is packaged relative to the source root. For a service-oriented layout, use `SourceLayout.SERVICE`:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from lambda_api_decorators_cdk import LambdaApi, SourceLayout
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
LambdaApi(
|
|
141
|
+
self,
|
|
142
|
+
"ServiceApi",
|
|
143
|
+
lambda_path="services",
|
|
144
|
+
source_layout=SourceLayout.SERVICE,
|
|
145
|
+
layers_path="layers",
|
|
146
|
+
)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
When `layers_path` is provided, each visible child directory is treated as a discoverable layer source. Explicit layer configuration remains available through `LambdaApiConfig`.
|
|
150
|
+
|
|
151
|
+
## Authorization and permissions
|
|
152
|
+
|
|
153
|
+
Register authorizers with a logical key and select the default authorizer for routes. A handler can override the default with `@authorizer("key")` or make itself public with `@public`.
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
from aws_cdk import aws_apigateway as apigateway
|
|
157
|
+
from lambda_api_decorators_cdk import LambdaApiConfig
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
authorizer = apigateway.TokenAuthorizer(self, "UsersAuthorizer", handler=authorizer_fn)
|
|
161
|
+
config = LambdaApiConfig(authorizers={"users": authorizer}, default_authorizer="users")
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The resource registries also allow decorated handlers to request least-privilege grants for registered DynamoDB tables and S3 buckets. See the [complete documentation](https://lambda-api-decorators.github.io/) for decorator syntax and supported access levels.
|
|
165
|
+
|
|
166
|
+
## Low-level builder
|
|
167
|
+
|
|
168
|
+
`ResourceBuilder` remains a supported lower-level API for callers that need direct control over the API root or build lifecycle:
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
from aws_cdk import Duration
|
|
172
|
+
from lambda_api_decorators_cdk import ResourceBuilder
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
builder = ResourceBuilder()
|
|
176
|
+
builder.set_default_timeout(Duration.seconds(30))
|
|
177
|
+
builder.add_common_environment("ENVIRONMENT", "production")
|
|
178
|
+
builder.build(self, rest_api.root, "lambdas")
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Prefer `LambdaApi` for new code. It owns API creation or reuse and delegates option resolution to isolated `ResourceBuilder` snapshots.
|
|
182
|
+
|
|
183
|
+
## Releases
|
|
184
|
+
|
|
185
|
+
The Git tag is the single source of truth for this package's version. For example, `v0.3.0` produces Python package version `0.3.0`. This repository is versioned independently from `lambda-api-decorators`.
|
|
186
|
+
|
|
187
|
+
To release from `main`, push a semantic version tag:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
git checkout main
|
|
191
|
+
git pull
|
|
192
|
+
git tag v0.3.0
|
|
193
|
+
git push origin v0.3.0
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Pushing the tag triggers the release workflow, which tests, builds, verifies the version, and publishes to PyPI using trusted publishing. The PyPI project must have a trusted publisher configured for this repository, the `release.yml` workflow, and the `pypi` GitHub environment.
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: lambda-api-decorators-cdk
|
|
3
|
-
Version: 0.4.0
|
|
4
|
-
Summary: AWS CDK integration for Lambda API Decorators. Generate AWS Lambda and API Gateway infrastructure from decorated Python handlers.
|
|
5
|
-
Author: Mateo Marcos, Emanuel Arguinarena, Lucas Picchi
|
|
6
|
-
License: MIT License
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2024 Lambda API Decorators CDK
|
|
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
|
-
Project-URL: Homepage, https://github.com/lambda-api-decorators/lambda-api-decorators-cdk
|
|
28
|
-
Project-URL: Repository, https://github.com/lambda-api-decorators/lambda-api-decorators-cdk
|
|
29
|
-
Project-URL: Bug Reports, https://github.com/lambda-api-decorators/lambda-api-decorators-cdk
|
|
30
|
-
Keywords: cdk,lambda,aws,api gateway,ast
|
|
31
|
-
Classifier: Development Status :: 2 - Pre-Alpha
|
|
32
|
-
Classifier: Intended Audience :: Developers
|
|
33
|
-
Classifier: Framework :: AWS CDK :: 2
|
|
34
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
35
|
-
Classifier: Topic :: Software Development :: Build Tools
|
|
36
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
38
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
39
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
41
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
42
|
-
Requires-Python: >=3.10
|
|
43
|
-
Description-Content-Type: text/markdown
|
|
44
|
-
License-File: LICENSE
|
|
45
|
-
Requires-Dist: aws-cdk.aws-lambda-python-alpha
|
|
46
|
-
Dynamic: license-file
|
|
47
|
-
|
|
48
|
-
# Lambda API Decorators CDK
|
|
49
|
-
|
|
50
|
-
## A library for AWS API Gateway/Lambda Proxy Integration
|
|
51
|
-
|
|
52
|
-
Lambda API Decorators CDK allows simplified resource creation for AWS Lambda functions and Rest API resources by using decorators and setting a builder with default, common or custom values for IAM Roles, Runtimes, Timeouts, Layers, Environment values, etc. This project relies abstract syntactic trees (ast) to analyze the code of your lambda functions and generate infraestructure accordingly.
|
|
53
|
-
|
|
54
|
-
### Installation
|
|
55
|
-
|
|
56
|
-
`lambda_api_decorators_cdk` is available from PyPI as `lambda-api-decorators-cdk`:
|
|
57
|
-
|
|
58
|
-
pip install lambda-api-decorators-cdk
|
|
59
|
-
|
|
60
|
-
Installation of [lambda-api-decorators](https://pypi.org/project/lambda-api-decorators/) is also required as a dependency for your lambda functions, since it provides the definition of decorators used within this module.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
### Example
|
|
64
|
-
|
|
65
|
-
```python
|
|
66
|
-
import lambda_api_decorators_cdk
|
|
67
|
-
or
|
|
68
|
-
from lambda_api_decorators_cdk import ResourceBuilder
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Builder instance
|
|
72
|
-
|
|
73
|
-
You may define a builder using lambda_api_decorators_cdk's constructor `ResourceBuilder`. This method returns an instance of the class that will be used to configure and create your Lambda Functions. By default, no parameters are required to instantiate the object, but custom options may be passed in advanced use cases.
|
|
74
|
-
|
|
75
|
-
```python
|
|
76
|
-
from lambda_api_decorators_cdk import ResourceBuilder
|
|
77
|
-
|
|
78
|
-
builder = ResourceBuilder()
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### Builder Configuration
|
|
82
|
-
|
|
83
|
-
If opted to, you can set default values for IAM Roles, Memory Size, Timeout, Runtime and VPC.
|
|
84
|
-
|
|
85
|
-
On the same note, support for common configuration that all the Lambda Functions will receive, such as Security Groups, Environment variables and Layers, is provided.
|
|
86
|
-
|
|
87
|
-
Lastly you can setup custom environments, layers, security groups, vpcs a Lambda Function will receive ONLY if they have the decorators defined.
|
|
88
|
-
|
|
89
|
-
```python
|
|
90
|
-
from lambda_api_decorators_cdk import ResourceBuilder
|
|
91
|
-
from aws_cdk import Duration
|
|
92
|
-
|
|
93
|
-
builder = ResourceBuilder()
|
|
94
|
-
builder.set_default_timeout(Duration.seconds(30))
|
|
95
|
-
builder.add_common_environment("DATABASE_URI", "something-db-related")
|
|
96
|
-
builder.add_custom_environment("URL-PREFIX", "lambda-api-decorators-cdk-") #Lambda Function should have decorator @environment("URL-PREFIX")
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### Building
|
|
100
|
-
|
|
101
|
-
Assuming you have already instantiated a Builder, configured it and ready to deploy your stack, then simply define the directory of your Lambda Functions and build!
|
|
102
|
-
|
|
103
|
-
Note: For a Lambda Function to be recognised and built, it has to have a decorator specifying the HTTP method it responds to. Decorators are defined in the [lambda-api-decorators](https://pypi.org/project/lambda-api-decorators/) package.
|
|
104
|
-
|
|
105
|
-
```python
|
|
106
|
-
[...] # Imports
|
|
107
|
-
|
|
108
|
-
class LambdaApiDecoratorsExampleStack(Stack):
|
|
109
|
-
|
|
110
|
-
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
|
|
111
|
-
super().__init__(scope, construct_id, **kwargs)
|
|
112
|
-
|
|
113
|
-
[...] # Instantiating builder, defining options and layers...
|
|
114
|
-
|
|
115
|
-
lambda_path = 'lambdas'
|
|
116
|
-
|
|
117
|
-
restapi = apigateway.RestApi(
|
|
118
|
-
self, 'lambda-api-decorators-RestApi',
|
|
119
|
-
rest_api_name= 'lambda-api-decorators-restApi')
|
|
120
|
-
root_resource = restapi.root
|
|
121
|
-
|
|
122
|
-
builder.build(self, root_resource, lambda_path, print_tree=True)
|
|
123
|
-
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## Maintainer releases
|
|
127
|
-
|
|
128
|
-
The Git tag is the single source of truth for this package's version. For
|
|
129
|
-
example, `v0.3.0` produces Python package version `0.3.0`. This repository is
|
|
130
|
-
versioned independently from `lambda-api-decorators`.
|
|
131
|
-
|
|
132
|
-
To release from `main`, choose and push a semantic version tag:
|
|
133
|
-
|
|
134
|
-
```bash
|
|
135
|
-
git checkout main
|
|
136
|
-
git pull
|
|
137
|
-
|
|
138
|
-
git tag v0.3.0
|
|
139
|
-
git push origin v0.3.0
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
Pushing the tag triggers the release workflow, which tests, builds, verifies
|
|
143
|
-
the version, and publishes with PyPI trusted publishing. The PyPI project must
|
|
144
|
-
have a trusted publisher configured for this repository, the `release.yml`
|
|
145
|
-
workflow, and the `pypi` GitHub environment.
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
# Lambda API Decorators CDK
|
|
2
|
-
|
|
3
|
-
## A library for AWS API Gateway/Lambda Proxy Integration
|
|
4
|
-
|
|
5
|
-
Lambda API Decorators CDK allows simplified resource creation for AWS Lambda functions and Rest API resources by using decorators and setting a builder with default, common or custom values for IAM Roles, Runtimes, Timeouts, Layers, Environment values, etc. This project relies abstract syntactic trees (ast) to analyze the code of your lambda functions and generate infraestructure accordingly.
|
|
6
|
-
|
|
7
|
-
### Installation
|
|
8
|
-
|
|
9
|
-
`lambda_api_decorators_cdk` is available from PyPI as `lambda-api-decorators-cdk`:
|
|
10
|
-
|
|
11
|
-
pip install lambda-api-decorators-cdk
|
|
12
|
-
|
|
13
|
-
Installation of [lambda-api-decorators](https://pypi.org/project/lambda-api-decorators/) is also required as a dependency for your lambda functions, since it provides the definition of decorators used within this module.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
### Example
|
|
17
|
-
|
|
18
|
-
```python
|
|
19
|
-
import lambda_api_decorators_cdk
|
|
20
|
-
or
|
|
21
|
-
from lambda_api_decorators_cdk import ResourceBuilder
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### Builder instance
|
|
25
|
-
|
|
26
|
-
You may define a builder using lambda_api_decorators_cdk's constructor `ResourceBuilder`. This method returns an instance of the class that will be used to configure and create your Lambda Functions. By default, no parameters are required to instantiate the object, but custom options may be passed in advanced use cases.
|
|
27
|
-
|
|
28
|
-
```python
|
|
29
|
-
from lambda_api_decorators_cdk import ResourceBuilder
|
|
30
|
-
|
|
31
|
-
builder = ResourceBuilder()
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Builder Configuration
|
|
35
|
-
|
|
36
|
-
If opted to, you can set default values for IAM Roles, Memory Size, Timeout, Runtime and VPC.
|
|
37
|
-
|
|
38
|
-
On the same note, support for common configuration that all the Lambda Functions will receive, such as Security Groups, Environment variables and Layers, is provided.
|
|
39
|
-
|
|
40
|
-
Lastly you can setup custom environments, layers, security groups, vpcs a Lambda Function will receive ONLY if they have the decorators defined.
|
|
41
|
-
|
|
42
|
-
```python
|
|
43
|
-
from lambda_api_decorators_cdk import ResourceBuilder
|
|
44
|
-
from aws_cdk import Duration
|
|
45
|
-
|
|
46
|
-
builder = ResourceBuilder()
|
|
47
|
-
builder.set_default_timeout(Duration.seconds(30))
|
|
48
|
-
builder.add_common_environment("DATABASE_URI", "something-db-related")
|
|
49
|
-
builder.add_custom_environment("URL-PREFIX", "lambda-api-decorators-cdk-") #Lambda Function should have decorator @environment("URL-PREFIX")
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Building
|
|
53
|
-
|
|
54
|
-
Assuming you have already instantiated a Builder, configured it and ready to deploy your stack, then simply define the directory of your Lambda Functions and build!
|
|
55
|
-
|
|
56
|
-
Note: For a Lambda Function to be recognised and built, it has to have a decorator specifying the HTTP method it responds to. Decorators are defined in the [lambda-api-decorators](https://pypi.org/project/lambda-api-decorators/) package.
|
|
57
|
-
|
|
58
|
-
```python
|
|
59
|
-
[...] # Imports
|
|
60
|
-
|
|
61
|
-
class LambdaApiDecoratorsExampleStack(Stack):
|
|
62
|
-
|
|
63
|
-
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
|
|
64
|
-
super().__init__(scope, construct_id, **kwargs)
|
|
65
|
-
|
|
66
|
-
[...] # Instantiating builder, defining options and layers...
|
|
67
|
-
|
|
68
|
-
lambda_path = 'lambdas'
|
|
69
|
-
|
|
70
|
-
restapi = apigateway.RestApi(
|
|
71
|
-
self, 'lambda-api-decorators-RestApi',
|
|
72
|
-
rest_api_name= 'lambda-api-decorators-restApi')
|
|
73
|
-
root_resource = restapi.root
|
|
74
|
-
|
|
75
|
-
builder.build(self, root_resource, lambda_path, print_tree=True)
|
|
76
|
-
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Maintainer releases
|
|
80
|
-
|
|
81
|
-
The Git tag is the single source of truth for this package's version. For
|
|
82
|
-
example, `v0.3.0` produces Python package version `0.3.0`. This repository is
|
|
83
|
-
versioned independently from `lambda-api-decorators`.
|
|
84
|
-
|
|
85
|
-
To release from `main`, choose and push a semantic version tag:
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
git checkout main
|
|
89
|
-
git pull
|
|
90
|
-
|
|
91
|
-
git tag v0.3.0
|
|
92
|
-
git push origin v0.3.0
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
Pushing the tag triggers the release workflow, which tests, builds, verifies
|
|
96
|
-
the version, and publishes with PyPI trusted publishing. The PyPI project must
|
|
97
|
-
have a trusted publisher configured for this repository, the `release.yml`
|
|
98
|
-
workflow, and the `pypi` GitHub environment.
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: lambda-api-decorators-cdk
|
|
3
|
-
Version: 0.4.0
|
|
4
|
-
Summary: AWS CDK integration for Lambda API Decorators. Generate AWS Lambda and API Gateway infrastructure from decorated Python handlers.
|
|
5
|
-
Author: Mateo Marcos, Emanuel Arguinarena, Lucas Picchi
|
|
6
|
-
License: MIT License
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2024 Lambda API Decorators CDK
|
|
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
|
-
Project-URL: Homepage, https://github.com/lambda-api-decorators/lambda-api-decorators-cdk
|
|
28
|
-
Project-URL: Repository, https://github.com/lambda-api-decorators/lambda-api-decorators-cdk
|
|
29
|
-
Project-URL: Bug Reports, https://github.com/lambda-api-decorators/lambda-api-decorators-cdk
|
|
30
|
-
Keywords: cdk,lambda,aws,api gateway,ast
|
|
31
|
-
Classifier: Development Status :: 2 - Pre-Alpha
|
|
32
|
-
Classifier: Intended Audience :: Developers
|
|
33
|
-
Classifier: Framework :: AWS CDK :: 2
|
|
34
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
35
|
-
Classifier: Topic :: Software Development :: Build Tools
|
|
36
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
38
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
39
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
41
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
42
|
-
Requires-Python: >=3.10
|
|
43
|
-
Description-Content-Type: text/markdown
|
|
44
|
-
License-File: LICENSE
|
|
45
|
-
Requires-Dist: aws-cdk.aws-lambda-python-alpha
|
|
46
|
-
Dynamic: license-file
|
|
47
|
-
|
|
48
|
-
# Lambda API Decorators CDK
|
|
49
|
-
|
|
50
|
-
## A library for AWS API Gateway/Lambda Proxy Integration
|
|
51
|
-
|
|
52
|
-
Lambda API Decorators CDK allows simplified resource creation for AWS Lambda functions and Rest API resources by using decorators and setting a builder with default, common or custom values for IAM Roles, Runtimes, Timeouts, Layers, Environment values, etc. This project relies abstract syntactic trees (ast) to analyze the code of your lambda functions and generate infraestructure accordingly.
|
|
53
|
-
|
|
54
|
-
### Installation
|
|
55
|
-
|
|
56
|
-
`lambda_api_decorators_cdk` is available from PyPI as `lambda-api-decorators-cdk`:
|
|
57
|
-
|
|
58
|
-
pip install lambda-api-decorators-cdk
|
|
59
|
-
|
|
60
|
-
Installation of [lambda-api-decorators](https://pypi.org/project/lambda-api-decorators/) is also required as a dependency for your lambda functions, since it provides the definition of decorators used within this module.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
### Example
|
|
64
|
-
|
|
65
|
-
```python
|
|
66
|
-
import lambda_api_decorators_cdk
|
|
67
|
-
or
|
|
68
|
-
from lambda_api_decorators_cdk import ResourceBuilder
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Builder instance
|
|
72
|
-
|
|
73
|
-
You may define a builder using lambda_api_decorators_cdk's constructor `ResourceBuilder`. This method returns an instance of the class that will be used to configure and create your Lambda Functions. By default, no parameters are required to instantiate the object, but custom options may be passed in advanced use cases.
|
|
74
|
-
|
|
75
|
-
```python
|
|
76
|
-
from lambda_api_decorators_cdk import ResourceBuilder
|
|
77
|
-
|
|
78
|
-
builder = ResourceBuilder()
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### Builder Configuration
|
|
82
|
-
|
|
83
|
-
If opted to, you can set default values for IAM Roles, Memory Size, Timeout, Runtime and VPC.
|
|
84
|
-
|
|
85
|
-
On the same note, support for common configuration that all the Lambda Functions will receive, such as Security Groups, Environment variables and Layers, is provided.
|
|
86
|
-
|
|
87
|
-
Lastly you can setup custom environments, layers, security groups, vpcs a Lambda Function will receive ONLY if they have the decorators defined.
|
|
88
|
-
|
|
89
|
-
```python
|
|
90
|
-
from lambda_api_decorators_cdk import ResourceBuilder
|
|
91
|
-
from aws_cdk import Duration
|
|
92
|
-
|
|
93
|
-
builder = ResourceBuilder()
|
|
94
|
-
builder.set_default_timeout(Duration.seconds(30))
|
|
95
|
-
builder.add_common_environment("DATABASE_URI", "something-db-related")
|
|
96
|
-
builder.add_custom_environment("URL-PREFIX", "lambda-api-decorators-cdk-") #Lambda Function should have decorator @environment("URL-PREFIX")
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### Building
|
|
100
|
-
|
|
101
|
-
Assuming you have already instantiated a Builder, configured it and ready to deploy your stack, then simply define the directory of your Lambda Functions and build!
|
|
102
|
-
|
|
103
|
-
Note: For a Lambda Function to be recognised and built, it has to have a decorator specifying the HTTP method it responds to. Decorators are defined in the [lambda-api-decorators](https://pypi.org/project/lambda-api-decorators/) package.
|
|
104
|
-
|
|
105
|
-
```python
|
|
106
|
-
[...] # Imports
|
|
107
|
-
|
|
108
|
-
class LambdaApiDecoratorsExampleStack(Stack):
|
|
109
|
-
|
|
110
|
-
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
|
|
111
|
-
super().__init__(scope, construct_id, **kwargs)
|
|
112
|
-
|
|
113
|
-
[...] # Instantiating builder, defining options and layers...
|
|
114
|
-
|
|
115
|
-
lambda_path = 'lambdas'
|
|
116
|
-
|
|
117
|
-
restapi = apigateway.RestApi(
|
|
118
|
-
self, 'lambda-api-decorators-RestApi',
|
|
119
|
-
rest_api_name= 'lambda-api-decorators-restApi')
|
|
120
|
-
root_resource = restapi.root
|
|
121
|
-
|
|
122
|
-
builder.build(self, root_resource, lambda_path, print_tree=True)
|
|
123
|
-
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## Maintainer releases
|
|
127
|
-
|
|
128
|
-
The Git tag is the single source of truth for this package's version. For
|
|
129
|
-
example, `v0.3.0` produces Python package version `0.3.0`. This repository is
|
|
130
|
-
versioned independently from `lambda-api-decorators`.
|
|
131
|
-
|
|
132
|
-
To release from `main`, choose and push a semantic version tag:
|
|
133
|
-
|
|
134
|
-
```bash
|
|
135
|
-
git checkout main
|
|
136
|
-
git pull
|
|
137
|
-
|
|
138
|
-
git tag v0.3.0
|
|
139
|
-
git push origin v0.3.0
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
Pushing the tag triggers the release workflow, which tests, builds, verifies
|
|
143
|
-
the version, and publishes with PyPI trusted publishing. The PyPI project must
|
|
144
|
-
have a trusted publisher configured for this repository, the `release.yml`
|
|
145
|
-
workflow, and the `pypi` GitHub environment.
|
{lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/.github/workflows/release.yml
RENAMED
|
File without changes
|
{lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/.github/workflows/tests.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_ast_helper.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_authorization_http.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_authorization_rest.py
RENAMED
|
File without changes
|
{lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_authorizer_config.py
RENAMED
|
File without changes
|
{lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_http_builder.py
RENAMED
|
File without changes
|
{lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_lambda_api.py
RENAMED
|
File without changes
|
{lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_lambda_api_config.py
RENAMED
|
File without changes
|
{lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_lambda_function.py
RENAMED
|
File without changes
|
|
File without changes
|
{lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_packaging_current.py
RENAMED
|
File without changes
|
|
File without changes
|
{lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_public_api.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_resource_graph.py
RENAMED
|
File without changes
|
|
File without changes
|
{lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_rest_builder.py
RENAMED
|
File without changes
|
{lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.1}/tests/test_source_layout.py
RENAMED
|
File without changes
|