Skip to content

Commit dede79c

Browse files
committed
merge from develop
2 parents 0ac3800 + 0447eec commit dede79c

File tree

6 files changed

+83
-37
lines changed

6 files changed

+83
-37
lines changed

.github/workflows/quality_check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
- name: Complexity baseline
7272
run: make complexity-baseline
7373
- name: Upload coverage to Codecov
74-
uses: codecov/codecov-action@7afa10ed9b269c561c2336fd862446844e0cbf71 # 4.2.0
74+
uses: codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed # 4.3.0
7575
with:
7676
file: ./coverage.xml
7777
env_vars: PYTHON

.github/workflows/secure_workflows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ jobs:
3232
- name: Checkout code
3333
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
3434
- name: Ensure 3rd party workflows have SHA pinned
35-
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@ba37328d4ea95eaf8b3bd6c6cef308f709a5f2ec # v3.0.3
35+
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@19ebcb0babbd282ae1822a0b9c28f3f1f25cea45 # v3.0.4
3636
with:
3737
allowlist: slsa-framework/slsa-github-generator

docs/core/event_handler/api_gateway.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,13 @@ You can use the `Response` class to have full control over the response. For exa
874874
--8<-- "examples/event_handler_rest/src/fine_grained_responses_output.json"
875875
```
876876

877+
???- note "Using `Response` with data validation?"
878+
When using the [data validation](#data-validation) feature with `enable_validation=True`, you must specify the concrete type for the `Response` class. This allows the validation middleware to infer the underlying type and perform validation correctly.
879+
880+
```python hl_lines="8 26 32"
881+
--8<-- "examples/event_handler_rest/src/data_validation_fine_grained_response.py"
882+
```
883+
877884
### Compress
878885

879886
You can compress with gzip and base64 encode your responses via `compress` parameter. You have the option to pass the `compress` parameter when working with a specific route or using the Response object.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from http import HTTPStatus
2+
from typing import Optional
3+
4+
import requests
5+
from pydantic import BaseModel, Field
6+
7+
from aws_lambda_powertools import Logger, Tracer
8+
from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response, content_types
9+
from aws_lambda_powertools.logging import correlation_paths
10+
from aws_lambda_powertools.utilities.typing import LambdaContext
11+
12+
tracer = Tracer()
13+
logger = Logger()
14+
app = APIGatewayRestResolver(enable_validation=True)
15+
16+
17+
class Todo(BaseModel):
18+
userId: int
19+
id_: Optional[int] = Field(alias="id", default=None)
20+
title: str
21+
completed: bool
22+
23+
24+
@app.get("/todos/<todo_id>")
25+
@tracer.capture_method
26+
def get_todo_by_id(todo_id: int) -> Response[Todo]:
27+
todo = requests.get(f"https://jsonplaceholder.typicode.com/todos/{todo_id}")
28+
todo.raise_for_status()
29+
return Response(
30+
status_code=HTTPStatus.OK.value,
31+
content_type=content_types.APPLICATION_JSON,
32+
body=todo.json(),
33+
)
34+
35+
36+
@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_REST)
37+
@tracer.capture_lambda_handler
38+
def lambda_handler(event: dict, context: LambdaContext) -> dict:
39+
return app.resolve(event, context)

poetry.lock

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ aws-cdk-lib = "^2.136.0"
7373
"aws-cdk.aws-apigatewayv2-alpha" = "^2.38.1-alpha.0"
7474
"aws-cdk.aws-apigatewayv2-integrations-alpha" = "^2.38.1-alpha.0"
7575
"aws-cdk.aws-apigatewayv2-authorizers-alpha" = "^2.38.1-alpha.0"
76-
"aws-cdk.aws-lambda-python-alpha" = "^2.135.0a0"
77-
"cdklabs.generative-ai-cdk-constructs" = "^0.1.107"
76+
"aws-cdk.aws-lambda-python-alpha" = "^2.136.0a0"
77+
"cdklabs.generative-ai-cdk-constructs" = "^0.1.110"
7878
pytest-benchmark = "^4.0.0"
7979
mypy-boto3-appconfig = "^1.34.58"
8080
mypy-boto3-cloudformation = "^1.34.77"
@@ -89,7 +89,7 @@ mypy-boto3-xray = "^1.34.0"
8989
types-requests = "^2.31.0"
9090
typing-extensions = "^4.6.2"
9191
mkdocs-material = "^9.5.17"
92-
filelock = "^3.13.3"
92+
filelock = "^3.13.4"
9393
checksumdir = "^1.2.0"
9494
mypy-boto3-appconfigdata = "^1.34.24"
9595
ijson = "^3.2.2"

0 commit comments

Comments
 (0)