Skip to content

Commit 5a5bf19

Browse files
author
Michael Brewer
authored
docs: fix syntax errors and line highlights (#1004)
1 parent 1f60f31 commit 5a5bf19

File tree

4 files changed

+59
-54
lines changed

4 files changed

+59
-54
lines changed

Diff for: docs/core/event_handler/api_gateway.md

+14-12
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ You can also nest paths as configured earlier in [our sample infrastructure](#re
298298
@app.get("/<message>/<name>")
299299
@tracer.capture_method
300300
def get_message(message, name):
301-
return {"message": f"{message}, {name}}"}
301+
return {"message": f"{message}, {name}"}
302302

303303
# You can continue to use other utilities just as before
304304
@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_REST)
@@ -461,7 +461,7 @@ def get_hello_you():
461461
payload = app.current_event.body
462462

463463
name = app.current_event.get_query_string_value(name="name", default_value="")
464-
return {"message": f"hello {name}}"}
464+
return {"message": f"hello {name}"}
465465

466466
def lambda_handler(event, context):
467467
return app.resolve(event, context)
@@ -481,7 +481,7 @@ def get_hello_you():
481481
headers_as_dict = app.current_event.headers
482482
name = app.current_event.get_header_value(name="X-Name", default_value="")
483483

484-
return {"message": f"hello {name}}"}
484+
return {"message": f"hello {name}"}
485485

486486
def lambda_handler(event, context):
487487
return app.resolve(event, context)
@@ -768,7 +768,8 @@ You can use the `Response` class to have full control over the response, for exa
768768

769769
=== "app.py"
770770

771-
```python hl_lines="10-14"
771+
```python hl_lines="11-16"
772+
import json
772773
from aws_lambda_powertools.event_handler.api_gateway import APIGatewayRestResolver, Response
773774

774775
app = APIGatewayRestResolver()
@@ -778,10 +779,11 @@ You can use the `Response` class to have full control over the response, for exa
778779
payload = json.dumps({"message": "I'm a teapot"})
779780
custom_headers = {"X-Custom": "X-Value"}
780781

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,
785787
)
786788

787789
def lambda_handler(event, context):
@@ -974,7 +976,7 @@ def lambda_handler(event, context):
974976

975977
You can instruct API Gateway handler to use a custom serializer to best suit your needs, for example take into account Enums when serializing.
976978

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"
978980
import json
979981
from enum import Enum
980982
from json import JSONEncoder
@@ -1025,7 +1027,7 @@ Let's assume you have `app.py` as your Lambda function entrypoint and routes in
10251027

10261028
We import **Router** instead of **APIGatewayRestResolver**; syntax wise is exactly the same.
10271029

1028-
```python hl_lines="4 8 12 15 21"
1030+
```python hl_lines="5 8 12 15 21"
10291031
import itertools
10301032
from typing import Dict
10311033

@@ -1221,7 +1223,7 @@ This sample project contains a Users function with two distinct set of routes, `
12211223

12221224
=== "src/users/main.py"
12231225

1224-
```python hl_lines="9 15-16"
1226+
```python hl_lines="8 14-15"
12251227
from typing import Dict
12261228

12271229
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
13561358
def test_lambda_handler(lambda_context):
13571359
minimal_event = {
13581360
"path": "/hello",
1359-
"httpMethod": "GET"
1361+
"httpMethod": "GET",
13601362
"requestContext": { # correlation ID
13611363
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
13621364
}

Diff for: docs/core/event_handler/appsync.md

+38-37
Original file line numberDiff line numberDiff line change
@@ -346,24 +346,24 @@ You can nest `app.resolver()` decorator multiple times when resolving fields wit
346346
=== "nested_mappings.py"
347347

348348
```python hl_lines="4 8 10-12 18"
349-
from aws_lambda_powertools import Logger, Tracer
349+
from aws_lambda_powertools import Logger, Tracer
350350

351-
from aws_lambda_powertools.logging import correlation_paths
352-
from aws_lambda_powertools.event_handler import AppSyncResolver
351+
from aws_lambda_powertools.logging import correlation_paths
352+
from aws_lambda_powertools.event_handler import AppSyncResolver
353353

354-
tracer = Tracer(service="sample_resolver")
355-
logger = Logger(service="sample_resolver")
356-
app = AppSyncResolver()
354+
tracer = Tracer(service="sample_resolver")
355+
logger = Logger(service="sample_resolver")
356+
app = AppSyncResolver()
357357

358-
@app.resolver(field_name="listLocations")
359-
@app.resolver(field_name="locations")
360-
def get_locations(name: str, description: str = ""):
361-
return name + description
358+
@app.resolver(field_name="listLocations")
359+
@app.resolver(field_name="locations")
360+
def get_locations(name: str, description: str = ""):
361+
return name + description
362362

363-
@logger.inject_lambda_context(correlation_id_path=correlation_paths.APPSYNC_RESOLVER)
364-
@tracer.capture_lambda_handler
365-
def lambda_handler(event, context):
366-
return app.resolve(event, context)
363+
@logger.inject_lambda_context(correlation_id_path=correlation_paths.APPSYNC_RESOLVER)
364+
@tracer.capture_lambda_handler
365+
def lambda_handler(event, context):
366+
return app.resolve(event, context)
367367
```
368368

369369
=== "schema.graphql"
@@ -396,7 +396,8 @@ You can nest `app.resolver()` decorator multiple times when resolving fields wit
396396

397397
For Lambda Python3.8+ runtime, this utility supports async functions when you use in conjunction with `asyncio.run`.
398398

399-
```python hl_lines="4 8 10-12 20" title="Resolving GraphQL resolvers async"
399+
```python hl_lines="5 9 11-13 21" title="Resolving GraphQL resolvers async"
400+
import asyncio
400401
from aws_lambda_powertools import Logger, Tracer
401402

402403
from aws_lambda_powertools.logging import correlation_paths
@@ -603,33 +604,34 @@ You can subclass `AppSyncResolverEvent` to bring your own set of methods to hand
603604

604605
=== "custom_model.py"
605606

606-
```python hl_lines="11-14 19 26"
607-
from aws_lambda_powertools import Logger, Tracer
607+
```python hl_lines="12-15 20 27"
608+
from aws_lambda_powertools import Logger, Tracer
608609

609-
from aws_lambda_powertools.logging import correlation_paths
610-
from aws_lambda_powertools.event_handler import AppSyncResolver
610+
from aws_lambda_powertools.logging import correlation_paths
611+
from aws_lambda_powertools.event_handler import AppSyncResolver
612+
from aws_lambda_powertools.utilities.data_classes.appsync_resolver_event import AppSyncResolverEvent
611613

612-
tracer = Tracer(service="sample_resolver")
613-
logger = Logger(service="sample_resolver")
614-
app = AppSyncResolver()
614+
tracer = Tracer(service="sample_resolver")
615+
logger = Logger(service="sample_resolver")
616+
app = AppSyncResolver()
615617

616618

617-
class MyCustomModel(AppSyncResolverEvent):
618-
@property
619-
def country_viewer(self) -> str:
620-
return self.request_headers.get("cloudfront-viewer-country")
619+
class MyCustomModel(AppSyncResolverEvent):
620+
@property
621+
def country_viewer(self) -> str:
622+
return self.request_headers.get("cloudfront-viewer-country")
621623

622-
@app.resolver(field_name="listLocations")
623-
@app.resolver(field_name="locations")
624-
def get_locations(name: str, description: str = ""):
625-
if app.current_event.country_viewer == "US":
626-
...
627-
return name + description
624+
@app.resolver(field_name="listLocations")
625+
@app.resolver(field_name="locations")
626+
def get_locations(name: str, description: str = ""):
627+
if app.current_event.country_viewer == "US":
628+
...
629+
return name + description
628630

629-
@logger.inject_lambda_context(correlation_id_path=correlation_paths.APPSYNC_RESOLVER)
630-
@tracer.capture_lambda_handler
631-
def lambda_handler(event, context):
632-
return app.resolve(event, context, data_model=MyCustomModel)
631+
@logger.inject_lambda_context(correlation_id_path=correlation_paths.APPSYNC_RESOLVER)
632+
@tracer.capture_lambda_handler
633+
def lambda_handler(event, context):
634+
return app.resolve(event, context, data_model=MyCustomModel)
633635
```
634636

635637
=== "schema.graphql"
@@ -820,7 +822,6 @@ Here's an example of how you can test your synchronous resolvers:
820822

821823
And an example for testing asynchronous resolvers. Note that this requires the `pytest-asyncio` package:
822824

823-
824825
=== "test_async_resolver.py"
825826

826827
```python

Diff for: docs/tutorial/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ Let's expand our application with custom metrics using AWS SDK to see how it wor
822822
def add_greeting_metric(service: str = "APP"):
823823
function_name = os.getenv("AWS_LAMBDA_FUNCTION_NAME", "undefined")
824824
service_dimension = {"Name": "service", "Value": service}
825-
function_dimension = {"Name": "function_name": "Value": function_name}
825+
function_dimension = {"Name": "function_name", "Value": function_name}
826826
is_cold_start = True
827827

828828
global cold_start

Diff for: docs/utilities/feature_flags.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ By default, we cache configuration retrieved from the Store for 5 seconds for pe
453453

454454
You can override `max_age` parameter when instantiating the store.
455455

456+
=== "app.py"
457+
456458
```python hl_lines="7"
457459
from aws_lambda_powertools.utilities.feature_flags import FeatureFlags, AppConfigStore
458460

@@ -677,11 +679,13 @@ Parameter | Default | Description
677679
**logger** | `logging.Logger` | Logger to use for debug. You can optionally supply an instance of Powertools Logger.
678680

679681

680-
```python hl_lines="19-25" title="AppConfigStore sample"
682+
```python hl_lines="21-27" title="AppConfigStore sample"
681683
from botocore.config import Config
682684

683685
import jmespath
684686

687+
from aws_lambda_powertools.utilities.feature_flags import AppConfigStore
688+
685689
boto_config = Config(read_timeout=10, retries={"total_max_attempts": 2})
686690

687691
# Custom JMESPath functions
@@ -715,9 +719,7 @@ You can unit test your feature flags locally and independently without setting u
715719
???+ warning
716720
This excerpt relies on `pytest` and `pytest-mock` dependencies.
717721

718-
```python hl_lines="9-11" title="Unit testing feature flags"
719-
from typing import Dict, List, Optional
720-
722+
```python hl_lines="7-9" title="Unit testing feature flags"
721723
from aws_lambda_powertools.utilities.feature_flags import FeatureFlags, AppConfigStore, RuleAction
722724

723725

0 commit comments

Comments
 (0)