@@ -298,7 +298,7 @@ You can also nest paths as configured earlier in [our sample infrastructure](#re
298
298
@app.get("/<message>/<name>")
299
299
@tracer.capture_method
300
300
def get_message(message, name):
301
- return {"message": f"{message}, {name}} "}
301
+ return {"message": f"{message}, {name}"}
302
302
303
303
# You can continue to use other utilities just as before
304
304
@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_REST)
@@ -461,7 +461,7 @@ def get_hello_you():
461
461
payload = app.current_event.body
462
462
463
463
name = app.current_event.get_query_string_value(name = " name" , default_value = " " )
464
- return {" message" : f " hello { name} } " }
464
+ return {" message" : f " hello { name} " }
465
465
466
466
def lambda_handler (event , context ):
467
467
return app.resolve(event, context)
@@ -481,7 +481,7 @@ def get_hello_you():
481
481
headers_as_dict = app.current_event.headers
482
482
name = app.current_event.get_header_value(name = " X-Name" , default_value = " " )
483
483
484
- return {" message" : f " hello { name} } " }
484
+ return {" message" : f " hello { name} " }
485
485
486
486
def lambda_handler (event , context ):
487
487
return app.resolve(event, context)
@@ -768,7 +768,8 @@ You can use the `Response` class to have full control over the response, for exa
768
768
769
769
=== "app.py"
770
770
771
- ```python hl_lines="10-14"
771
+ ```python hl_lines="11-16"
772
+ import json
772
773
from aws_lambda_powertools.event_handler.api_gateway import APIGatewayRestResolver, Response
773
774
774
775
app = APIGatewayRestResolver()
@@ -778,10 +779,11 @@ You can use the `Response` class to have full control over the response, for exa
778
779
payload = json.dumps({"message": "I'm a teapot"})
779
780
custom_headers = {"X-Custom": "X-Value"}
780
781
781
- return Response(status_code=418,
782
- content_type="application/json",
783
- body=payload,
784
- headers=custom_headers
782
+ return Response(
783
+ status_code=418,
784
+ content_type="application/json",
785
+ body=payload,
786
+ headers=custom_headers,
785
787
)
786
788
787
789
def lambda_handler(event, context):
@@ -974,7 +976,7 @@ def lambda_handler(event, context):
974
976
975
977
You can instruct API Gateway handler to use a custom serializer to best suit your needs, for example take into account Enums when serializing.
976
978
977
- ``` python hl_lines="19-20 24 " title="Using a custom JSON serializer for responses"
979
+ ``` python hl_lines="21-22 26 " title="Using a custom JSON serializer for responses"
978
980
import json
979
981
from enum import Enum
980
982
from json import JSONEncoder
@@ -1025,7 +1027,7 @@ Let's assume you have `app.py` as your Lambda function entrypoint and routes in
1025
1027
1026
1028
We import **Router** instead of **APIGatewayRestResolver**; syntax wise is exactly the same.
1027
1029
1028
- ```python hl_lines="4 8 12 15 21"
1030
+ ```python hl_lines="5 8 12 15 21"
1029
1031
import itertools
1030
1032
from typing import Dict
1031
1033
@@ -1221,7 +1223,7 @@ This sample project contains a Users function with two distinct set of routes, `
1221
1223
1222
1224
=== "src/users/main.py"
1223
1225
1224
- ```python hl_lines="9 15-16 "
1226
+ ```python hl_lines="8 14-15 "
1225
1227
from typing import Dict
1226
1228
1227
1229
from aws_lambda_powertools import Logger, Tracer
@@ -1356,7 +1358,7 @@ You can test your routes by passing a proxy event request where `path` and `http
1356
1358
def test_lambda_handler(lambda_context):
1357
1359
minimal_event = {
1358
1360
"path": "/hello",
1359
- "httpMethod": "GET"
1361
+ "httpMethod": "GET",
1360
1362
"requestContext": { # correlation ID
1361
1363
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
1362
1364
}
0 commit comments