lambda-api-decorators-cdk 0.4.0__tar.gz → 0.4.4__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.
Files changed (54) hide show
  1. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/.github/workflows/release.yml +1 -1
  2. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/.github/workflows/tests.yml +3 -1
  3. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/AGENTS.md +2 -2
  4. lambda_api_decorators_cdk-0.4.4/PKG-INFO +197 -0
  5. lambda_api_decorators_cdk-0.4.4/README.md +149 -0
  6. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/pyproject.toml +4 -3
  7. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/src/lambda_api_decorators_cdk/lambda_api_config.py +122 -6
  8. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/src/lambda_api_decorators_cdk/resource_builder.py +188 -24
  9. lambda_api_decorators_cdk-0.4.4/src/lambda_api_decorators_cdk.egg-info/PKG-INFO +197 -0
  10. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/src/lambda_api_decorators_cdk.egg-info/SOURCES.txt +2 -0
  11. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/src/lambda_api_decorators_cdk.egg-info/scm_file_list.json +2 -0
  12. lambda_api_decorators_cdk-0.4.4/src/lambda_api_decorators_cdk.egg-info/scm_version.json +8 -0
  13. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_authorization_diagnostics.py +9 -8
  14. lambda_api_decorators_cdk-0.4.4/tests/test_config_override_diagnostics.py +269 -0
  15. lambda_api_decorators_cdk-0.4.4/tests/test_config_resource_registries.py +350 -0
  16. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_lambda_api_config.py +10 -9
  17. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_resource_builder_state.py +4 -4
  18. lambda_api_decorators_cdk-0.4.0/PKG-INFO +0 -145
  19. lambda_api_decorators_cdk-0.4.0/README.md +0 -98
  20. lambda_api_decorators_cdk-0.4.0/src/lambda_api_decorators_cdk.egg-info/PKG-INFO +0 -145
  21. lambda_api_decorators_cdk-0.4.0/src/lambda_api_decorators_cdk.egg-info/scm_version.json +0 -8
  22. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/.gitignore +0 -0
  23. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/LICENSE +0 -0
  24. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/setup.cfg +0 -0
  25. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/src/lambda_api_decorators_cdk/__init__.py +0 -0
  26. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/src/lambda_api_decorators_cdk/api_type.py +0 -0
  27. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/src/lambda_api_decorators_cdk/ast_helper.py +0 -0
  28. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/src/lambda_api_decorators_cdk/lambda_api.py +0 -0
  29. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/src/lambda_api_decorators_cdk/source_layout.py +0 -0
  30. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/src/lambda_api_decorators_cdk.egg-info/dependency_links.txt +0 -0
  31. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/src/lambda_api_decorators_cdk.egg-info/requires.txt +0 -0
  32. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/src/lambda_api_decorators_cdk.egg-info/top_level.txt +0 -0
  33. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/conftest.py +0 -0
  34. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_ast_decorator_invocations.py +0 -0
  35. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_ast_helper.py +0 -0
  36. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_auth_ast.py +0 -0
  37. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_authorization_http.py +0 -0
  38. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_authorization_lambda_api.py +0 -0
  39. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_authorization_resolution.py +0 -0
  40. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_authorization_rest.py +0 -0
  41. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_authorizer_config.py +0 -0
  42. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_http_builder.py +0 -0
  43. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_lambda_api.py +0 -0
  44. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_lambda_function.py +0 -0
  45. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_layer_autodiscovery.py +0 -0
  46. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_packaging_current.py +0 -0
  47. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_permission_resolution.py +0 -0
  48. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_public_api.py +0 -0
  49. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_python_compatibility.py +0 -0
  50. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_resource_builder_options.py +0 -0
  51. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_resource_graph.py +0 -0
  52. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_resource_registries.py +0 -0
  53. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_rest_builder.py +0 -0
  54. {lambda_api_decorators_cdk-0.4.0 → lambda_api_decorators_cdk-0.4.4}/tests/test_source_layout.py +0 -0
@@ -39,7 +39,7 @@ jobs:
39
39
  - name: Install test and build dependencies
40
40
  run: |
41
41
  python -m pip install --upgrade pip
42
- python -m pip install build pytest setuptools-scm
42
+ python -m pip install build pytest setuptools-scm lambda-api-decorators
43
43
  python -m pip install .
44
44
 
45
45
  - name: Run tests
@@ -2,7 +2,9 @@ name: Tests
2
2
 
3
3
  on:
4
4
  push:
5
+ branches: [main]
5
6
  pull_request:
7
+ branches: [main]
6
8
 
7
9
  permissions:
8
10
  contents: read
@@ -27,7 +29,7 @@ jobs:
27
29
  - name: Install package and test dependencies
28
30
  run: |
29
31
  python -m pip install --upgrade pip
30
- python -m pip install --editable . pytest tomli
32
+ python -m pip install --editable . lambda-api-decorators pytest tomli
31
33
 
32
34
  - name: Verify package import
33
35
  run: python -c "import lambda_api_decorators_cdk"
@@ -10,7 +10,7 @@ The project goal is:
10
10
 
11
11
  GitHub organization:
12
12
 
13
- `lambda-api-decorators`
13
+ `infrastructure-as-decorator`
14
14
 
15
15
  Package:
16
16
 
@@ -22,7 +22,7 @@ Python module:
22
22
 
23
23
  Project documentation:
24
24
 
25
- `https://lambda-api-decorators.github.io/`
25
+ `https://infrastructure-as-decorator.github.io/`
26
26
 
27
27
  ## Design principles
28
28
 
@@ -0,0 +1,197 @@
1
+ Metadata-Version: 2.4
2
+ Name: lambda-api-decorators-cdk
3
+ Version: 0.4.4
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://infrastructure-as-decorator.github.io/
28
+ Project-URL: Documentation, https://infrastructure-as-decorator.github.io/docs/api-reference/index
29
+ Project-URL: Repository, https://github.com/infrastructure-as-decorator/lambda-api-decorators-cdk
30
+ Project-URL: Bug Reports, https://github.com/infrastructure-as-decorator/lambda-api-decorators-cdk/issues
31
+ Keywords: cdk,lambda,aws,api gateway,ast
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.10
39
+ Classifier: Programming Language :: Python :: 3.11
40
+ Classifier: Programming Language :: Python :: 3.12
41
+ Classifier: Programming Language :: Python :: 3.13
42
+ Classifier: Programming Language :: Python :: 3.14
43
+ Requires-Python: >=3.10
44
+ Description-Content-Type: text/markdown
45
+ License-File: LICENSE
46
+ Requires-Dist: aws-cdk.aws-lambda-python-alpha
47
+ Dynamic: license-file
48
+
49
+ # Lambda API Decorators CDK
50
+
51
+ 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.
52
+
53
+ The complete cross-package guides and architecture documentation are available at [infrastructure-as-decorator.github.io](https://infrastructure-as-decorator.github.io/).
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ pip install lambda-api-decorators-cdk
59
+ ```
60
+
61
+ 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.
62
+
63
+ ## Quick start
64
+
65
+ `LambdaApi` is the recommended high-level construct. It creates a REST API by default and discovers decorated handlers below `lambda_path`.
66
+
67
+ ```python
68
+ from aws_cdk import Stack
69
+ from constructs import Construct
70
+
71
+ from lambda_api_decorators_cdk import LambdaApi
72
+
73
+
74
+ class ExampleStack(Stack):
75
+ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
76
+ super().__init__(scope, construct_id, **kwargs)
77
+
78
+ LambdaApi(self, "ExampleApi", lambda_path="lambdas")
79
+ ```
80
+
81
+ A handler must include an HTTP method decorator from `lambda-api-decorators`:
82
+
83
+ ```python
84
+ from lambda_api_decorators import GET
85
+
86
+
87
+ @GET("/hello")
88
+ def hello(event, context):
89
+ return {"statusCode": 200, "body": "Hello, world!"}
90
+ ```
91
+
92
+ `lambda_path` is resolved from the directory where CDK is run. Files without a supported route decorator are ignored.
93
+
94
+ ## API types and imported APIs
95
+
96
+ REST is the default. Select an HTTP API with `ApiType.HTTP`, or provide an existing supported API and let the construct infer its type.
97
+
98
+ ```python
99
+ from aws_cdk import aws_apigateway as apigateway
100
+ from lambda_api_decorators_cdk import ApiType, LambdaApi
101
+
102
+
103
+ LambdaApi(self, "HttpApi", lambda_path="lambdas", api_type=ApiType.HTTP)
104
+
105
+ existing_rest_api = apigateway.RestApi(self, "ExistingRestApi")
106
+ LambdaApi(self, "ExistingApiRoutes", lambda_path="lambdas", api=existing_rest_api)
107
+ ```
108
+
109
+ Created and imported REST APIs are supported. Concrete `aws_apigatewayv2.HttpApi` instances are supported for HTTP APIs.
110
+
111
+ ## Reusable configuration
112
+
113
+ Use `LambdaApiConfig` for defaults and named resources shared by one or more `LambdaApi` constructs. Configuration must be complete before constructing the API.
114
+
115
+ ```python
116
+ from aws_cdk import Duration, aws_lambda as lambda_
117
+ from lambda_api_decorators_cdk import LambdaApi, LambdaApiConfig
118
+
119
+
120
+ config = LambdaApiConfig(
121
+ runtime=lambda_.Runtime.PYTHON_3_12,
122
+ timeout=Duration.seconds(30),
123
+ memory_size=512,
124
+ environment={"ENVIRONMENT": "production"},
125
+ )
126
+ config.add_custom_environment("PAYMENTS_URL", "https://payments.example.com")
127
+
128
+ LambdaApi(self, "ConfiguredApi", lambda_path="lambdas", config=config)
129
+ ```
130
+
131
+ `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.
132
+
133
+ ## Source layout and layers
134
+
135
+ By default, each handler is packaged relative to the source root. For a service-oriented layout, use `SourceLayout.SERVICE`:
136
+
137
+ ```python
138
+ from lambda_api_decorators_cdk import LambdaApi, SourceLayout
139
+
140
+
141
+ LambdaApi(
142
+ self,
143
+ "ServiceApi",
144
+ lambda_path="services",
145
+ source_layout=SourceLayout.SERVICE,
146
+ layers_path="layers",
147
+ )
148
+ ```
149
+
150
+ When `layers_path` is provided, each visible child directory is treated as a discoverable layer source. Explicit layer configuration remains available through `LambdaApiConfig`.
151
+
152
+ ## Authorization and permissions
153
+
154
+ 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`.
155
+
156
+ ```python
157
+ from aws_cdk import aws_apigateway as apigateway
158
+ from lambda_api_decorators_cdk import LambdaApiConfig
159
+
160
+
161
+ authorizer = apigateway.TokenAuthorizer(self, "UsersAuthorizer", handler=authorizer_fn)
162
+ config = LambdaApiConfig(authorizers={"users": authorizer}, default_authorizer="users")
163
+ ```
164
+
165
+ The resource registries also allow decorated handlers to request least-privilege grants for registered DynamoDB tables and S3 buckets. See the [complete documentation](https://infrastructure-as-decorator.github.io/docs/api-reference/index) for decorator syntax and supported access levels.
166
+
167
+ ## Low-level builder
168
+
169
+ `ResourceBuilder` remains a supported lower-level API for callers that need direct control over the API root or build lifecycle:
170
+
171
+ ```python
172
+ from aws_cdk import Duration
173
+ from lambda_api_decorators_cdk import ResourceBuilder
174
+
175
+
176
+ builder = ResourceBuilder()
177
+ builder.set_default_timeout(Duration.seconds(30))
178
+ builder.add_common_environment("ENVIRONMENT", "production")
179
+ builder.build(self, rest_api.root, "lambdas")
180
+ ```
181
+
182
+ Prefer `LambdaApi` for new code. It owns API creation or reuse and delegates option resolution to isolated `ResourceBuilder` snapshots.
183
+
184
+ ## Releases
185
+
186
+ 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`.
187
+
188
+ To release from `main`, push a semantic version tag:
189
+
190
+ ```bash
191
+ git checkout main
192
+ git pull
193
+ git tag v0.3.0
194
+ git push origin v0.3.0
195
+ ```
196
+
197
+ 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 [infrastructure-as-decorator.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://infrastructure-as-decorator.github.io/docs/api-reference/index) 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.
@@ -84,9 +84,10 @@ dependencies = [
84
84
  # maintainers, and where to support the project financially. The key is
85
85
  # what's used to render the link text on PyPI.
86
86
  [project.urls]
87
- "Homepage" = "https://github.com/lambda-api-decorators/lambda-api-decorators-cdk"
88
- "Repository" = "https://github.com/lambda-api-decorators/lambda-api-decorators-cdk"
89
- "Bug Reports" = "https://github.com/lambda-api-decorators/lambda-api-decorators-cdk"
87
+ Homepage = "https://infrastructure-as-decorator.github.io/"
88
+ Documentation = "https://infrastructure-as-decorator.github.io/docs/api-reference/index"
89
+ Repository = "https://github.com/infrastructure-as-decorator/lambda-api-decorators-cdk"
90
+ "Bug Reports" = "https://github.com/infrastructure-as-decorator/lambda-api-decorators-cdk/issues"
90
91
 
91
92
  # The following would provide a command line executable called `sample`
92
93
  # which executes the function `main` from this package when invoked.
@@ -1,4 +1,5 @@
1
- from typing import Mapping, Optional, Sequence
1
+ from collections.abc import Mapping
2
+ from typing import Optional, Sequence
2
3
 
3
4
  from aws_cdk import Duration
4
5
  from aws_cdk import aws_ec2 as ec2
@@ -29,7 +30,29 @@ class LambdaApiConfig:
29
30
  s3_buckets: Optional[Mapping[str, s3.IBucket]] = None,
30
31
  authorizers: Optional[Mapping[str, object]] = None,
31
32
  default_authorizer: Optional[str] = None,
33
+ default_runtime: Optional[str] = None,
34
+ default_role: Optional[iam.IRole] = None,
35
+ common_environment: Optional[Mapping[str, str]] = None,
36
+ role_registry: Optional[Mapping[str, iam.IRole]] = None,
37
+ environment_registry: Optional[Mapping[str, Mapping[str, str]]] = None,
38
+ layer_registry: Optional[Mapping[str, lambda_.ILayerVersion]] = None,
39
+ security_group_registry: Optional[Mapping[str, ec2.ISecurityGroup]] = None,
40
+ vpc_registry: Optional[Mapping[str, ec2.IVpc]] = None,
41
+ dynamodb_table_registry: Optional[Mapping[str, dynamodb.ITable]] = None,
42
+ s3_bucket_registry: Optional[Mapping[str, s3.IBucket]] = None,
43
+ authorizer_registry: Optional[Mapping[str, object]] = None,
32
44
  ) -> None:
45
+ if default_runtime is not None:
46
+ self._validate_runtime_name(default_runtime)
47
+ if default_runtime is not None and runtime is not None:
48
+ raise ValueError("runtime and default_runtime cannot both be supplied")
49
+ if default_role is not None and role is not None:
50
+ raise ValueError("role and default_role cannot both be supplied")
51
+ if common_environment is not None and environment is not None:
52
+ raise ValueError(
53
+ "environment and common_environment cannot both be supplied"
54
+ )
55
+
33
56
  self._default_runtime = runtime
34
57
  self._default_timeout = timeout
35
58
  self._default_memory_size = memory_size
@@ -40,7 +63,13 @@ class LambdaApiConfig:
40
63
  self._common_security_groups = (
41
64
  list(security_groups) if security_groups is not None else []
42
65
  )
43
- self._common_environments = dict(environment) if environment is not None else {}
66
+ self._common_environments = dict(
67
+ common_environment if common_environment is not None else environment or {}
68
+ )
69
+ if default_runtime is not None:
70
+ self._default_runtime = default_runtime
71
+ if default_role is not None:
72
+ self._default_role = default_role
44
73
 
45
74
  self._custom_runtimes = {}
46
75
  self._custom_roles = {}
@@ -61,6 +90,49 @@ class LambdaApiConfig:
61
90
  self._default_authorizer = None
62
91
  self.set_default_authorizer(default_authorizer)
63
92
 
93
+ for key, value in (role_registry or {}).items():
94
+ self.register_role(key, value)
95
+ for key, value in (environment_registry or {}).items():
96
+ self.register_environment(key, value)
97
+ for key, value in (layer_registry or {}).items():
98
+ self.register_layer(key, value)
99
+ for key, value in (security_group_registry or {}).items():
100
+ self.register_security_group(key, value)
101
+ for key, value in (vpc_registry or {}).items():
102
+ self.register_vpc(key, value)
103
+ for key, value in (dynamodb_table_registry or {}).items():
104
+ self.register_dynamodb_table(key, value)
105
+ for key, value in (s3_bucket_registry or {}).items():
106
+ self.register_s3_bucket(key, value)
107
+ for key, value in (authorizer_registry or {}).items():
108
+ self.register_authorizer(key, value)
109
+
110
+ @staticmethod
111
+ def _validate_runtime_name(runtime: str) -> None:
112
+ supported = {
113
+ "python3.10", "python3.11", "python3.12", "python3.13", "python3.14"
114
+ }
115
+ if not isinstance(runtime, str):
116
+ raise TypeError("runtime must be a string")
117
+ if runtime not in supported:
118
+ raise ValueError(
119
+ "runtime must be one of {}".format(", ".join(sorted(supported)))
120
+ )
121
+
122
+ @staticmethod
123
+ def _validate_registry_key(key: str, registry_name: str) -> None:
124
+ if not isinstance(key, str):
125
+ raise TypeError(f"{registry_name} keys must be strings")
126
+ if not key.strip():
127
+ raise ValueError(f"{registry_name} keys must not be empty or whitespace")
128
+
129
+ @classmethod
130
+ def _register(cls, registry: dict, key: str, value, registry_name: str) -> None:
131
+ cls._validate_registry_key(key, registry_name)
132
+ if key in registry:
133
+ raise ValueError(f"{registry_name} key {key!r} is already registered")
134
+ registry[key] = value
135
+
64
136
  def set_default_runtime(self, runtime: Optional[lambda_.Runtime]) -> None:
65
137
  self._default_runtime = runtime
66
138
 
@@ -90,9 +162,6 @@ class LambdaApiConfig:
90
162
  if security_group not in self._common_security_groups:
91
163
  self._common_security_groups.append(security_group)
92
164
 
93
- def add_common_environment(self, key: str, value: str) -> None:
94
- self._common_environments[key] = value
95
-
96
165
  def add_custom_runtime(self, key: str, runtime: lambda_.Runtime) -> None:
97
166
  self._custom_runtimes[key] = runtime
98
167
 
@@ -141,6 +210,50 @@ class LambdaApiConfig:
141
210
  raise ValueError(f"Authorizer key {key!r} is already registered")
142
211
  self._authorizers[key] = authorizer
143
212
 
213
+ def register_role(self, key: str, role: iam.IRole) -> None:
214
+ self._register(self._custom_roles, key, role, "role registry")
215
+
216
+ def register_environment(self, key: str, value: Mapping[str, str]) -> None:
217
+ if not isinstance(value, Mapping):
218
+ raise TypeError("environment registry values must be mappings")
219
+ self._register(self._custom_environments, key, dict(value), "environment registry")
220
+
221
+ def register_layer(self, key: str, layer: lambda_.ILayerVersion) -> None:
222
+ self._register(self._custom_layers, key, layer, "layer registry")
223
+
224
+ def register_security_group(self, key: str, security_group: ec2.ISecurityGroup) -> None:
225
+ self._register(
226
+ self._custom_security_groups, key, security_group, "security group registry"
227
+ )
228
+
229
+ def register_vpc(
230
+ self,
231
+ key: str,
232
+ vpc: ec2.IVpc,
233
+ vpc_subnets: Optional[ec2.SubnetSelection] = None,
234
+ ) -> None:
235
+ self._register(self._custom_vpcs, key, (vpc, vpc_subnets), "vpc registry")
236
+
237
+ def register_dynamodb_table(self, key: str, table: dynamodb.ITable) -> None:
238
+ self._register(self._dynamodb_tables, key, table, "dynamodb table registry")
239
+
240
+ def register_s3_bucket(self, key: str, bucket: s3.IBucket) -> None:
241
+ self._register(self._s3_buckets, key, bucket, "s3 bucket registry")
242
+
243
+ def register_authorizer(self, key: str, authorizer: object) -> None:
244
+ self._validate_registry_key(key, "authorizer registry")
245
+ interfaces = getattr(authorizer, "__jsii_ifaces__", ()) if authorizer is not None else ()
246
+ supported = {
247
+ "aws_cdk.aws_apigateway.IAuthorizer",
248
+ "aws_cdk.aws_apigatewayv2.IHttpRouteAuthorizer",
249
+ }
250
+ if not any(
251
+ f"{interface.__module__}.{interface.__name__}" in supported
252
+ for interface in interfaces
253
+ ):
254
+ raise TypeError("authorizer registry values must be CDK authorizers")
255
+ self._register(self._authorizers, key, authorizer, "authorizer registry")
256
+
144
257
  def set_default_authorizer(self, key: Optional[str]) -> None:
145
258
  if key is None:
146
259
  self._default_authorizer = None
@@ -179,7 +292,10 @@ class LambdaApiConfig:
179
292
  custom_runtimes=dict(self._custom_runtimes),
180
293
  custom_roles=dict(self._custom_roles),
181
294
  custom_layers=dict(self._custom_layers),
182
- custom_environments=dict(self._custom_environments),
295
+ custom_environments={
296
+ key: dict(value) if isinstance(value, Mapping) else value
297
+ for key, value in self._custom_environments.items()
298
+ },
183
299
  custom_security_groups=dict(self._custom_security_groups),
184
300
  custom_vpcs=dict(self._custom_vpcs),
185
301
  dynamodb_tables=dict(self._dynamodb_tables),