Skip to content

Commit 9d0f3ee

Browse files
author
Michael Brewer
committed
fix(docs): Add final missing code and fixes
Changes: - Update make tasks to include shared code examples - Add missing dubug mode example - Correct python hl_lines spacing - Fix line highlights for validation and jmepath examples - Move schema.py into examples for Validation
1 parent 51ddc84 commit 9d0f3ee

File tree

10 files changed

+163
-150
lines changed

10 files changed

+163
-150
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,16 @@ mypy:
9292
poetry run mypy --pretty aws_lambda_powertools
9393

9494
format-examples:
95+
poetry run isort docs/shared
96+
poetry run black docs/shared/*.py
9597
poetry run isort docs/examples
9698
poetry run black docs/examples/*/*.py
9799
poetry run black docs/examples/*/*/*.py
98100
poetry run black docs/examples/*/*/*/*.py
99101
poetry run black docs/examples/*/*/*/*/*.py
100102

101103
lint-examples:
104+
poetry run python3 -m py_compile docs/shared/*.py
102105
poetry run python3 -m py_compile docs/examples/*/*.py
103106
poetry run python3 -m py_compile docs/examples/*/*/*.py
104107
poetry run python3 -m py_compile docs/examples/*/*/*/*.py

docs/core/event_handler/api_gateway.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ This sample project contains a Users function with two distinct set of routes, `
683683

684684
=== "tests/functional/test_users.py"
685685

686-
```python hl_lines="3"
686+
```python hl_lines="3"
687687
--8<-- "docs/examples/core/event_handler/api_gateway/layout/test_users.py"
688688
```
689689

docs/examples/index/debug_mode.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from aws_lambda_powertools.logging.logger import set_package_logger
2+
3+
set_package_logger() # (1)
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
INPUT = {
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"definitions": {
4+
"AWSAPICallViaCloudTrail": {
5+
"properties": {
6+
"additionalEventData": {"$ref": "#/definitions/AdditionalEventData"},
7+
"awsRegion": {"type": "string"},
8+
"errorCode": {"type": "string"},
9+
"errorMessage": {"type": "string"},
10+
"eventID": {"type": "string"},
11+
"eventName": {"type": "string"},
12+
"eventSource": {"type": "string"},
13+
"eventTime": {"format": "date-time", "type": "string"},
14+
"eventType": {"type": "string"},
15+
"eventVersion": {"type": "string"},
16+
"recipientAccountId": {"type": "string"},
17+
"requestID": {"type": "string"},
18+
"requestParameters": {"$ref": "#/definitions/RequestParameters"},
19+
"resources": {"items": {"type": "object"}, "type": "array"},
20+
"responseElements": {"type": ["object", "null"]},
21+
"sourceIPAddress": {"type": "string"},
22+
"userAgent": {"type": "string"},
23+
"userIdentity": {"$ref": "#/definitions/UserIdentity"},
24+
"vpcEndpointId": {"type": "string"},
25+
"x-amazon-open-api-schema-readOnly": {"type": "boolean"},
26+
},
27+
"required": [
28+
"eventID",
29+
"awsRegion",
30+
"eventVersion",
31+
"responseElements",
32+
"sourceIPAddress",
33+
"eventSource",
34+
"requestParameters",
35+
"resources",
36+
"userAgent",
37+
"readOnly",
38+
"userIdentity",
39+
"eventType",
40+
"additionalEventData",
41+
"vpcEndpointId",
42+
"requestID",
43+
"eventTime",
44+
"eventName",
45+
"recipientAccountId",
46+
],
47+
"type": "object",
48+
},
49+
"AdditionalEventData": {
50+
"properties": {
51+
"objectRetentionInfo": {"$ref": "#/definitions/ObjectRetentionInfo"},
52+
"x-amz-id-2": {"type": "string"},
53+
},
54+
"required": ["x-amz-id-2"],
55+
"type": "object",
56+
},
57+
"Attributes": {
58+
"properties": {
59+
"creationDate": {"format": "date-time", "type": "string"},
60+
"mfaAuthenticated": {"type": "string"},
61+
},
62+
"required": ["mfaAuthenticated", "creationDate"],
63+
"type": "object",
64+
},
65+
"LegalHoldInfo": {
66+
"properties": {
67+
"isUnderLegalHold": {"type": "boolean"},
68+
"lastModifiedTime": {"format": "int64", "type": "integer"},
69+
},
70+
"type": "object",
71+
},
72+
"ObjectRetentionInfo": {
73+
"properties": {
74+
"legalHoldInfo": {"$ref": "#/definitions/LegalHoldInfo"},
75+
"retentionInfo": {"$ref": "#/definitions/RetentionInfo"},
76+
},
77+
"type": "object",
78+
},
79+
"RequestParameters": {
80+
"properties": {
81+
"bucketName": {"type": "string"},
82+
"key": {"type": "string"},
83+
"legal-hold": {"type": "string"},
84+
"retention": {"type": "string"},
85+
},
86+
"required": ["bucketName", "key"],
87+
"type": "object",
88+
},
89+
"RetentionInfo": {
90+
"properties": {
91+
"lastModifiedTime": {"format": "int64", "type": "integer"},
92+
"retainUntilMode": {"type": "string"},
93+
"retainUntilTime": {"format": "int64", "type": "integer"},
94+
},
95+
"type": "object",
96+
},
97+
"SessionContext": {
98+
"properties": {"attributes": {"$ref": "#/definitions/Attributes"}},
99+
"required": ["attributes"],
100+
"type": "object",
101+
},
102+
"UserIdentity": {
103+
"properties": {
104+
"accessKeyId": {"type": "string"},
105+
"accountId": {"type": "string"},
106+
"arn": {"type": "string"},
107+
"principalId": {"type": "string"},
108+
"sessionContext": {"$ref": "#/definitions/SessionContext"},
109+
"type": {"type": "string"},
110+
},
111+
"required": ["accessKeyId", "sessionContext", "accountId", "principalId", "type", "arn"],
112+
"type": "object",
113+
},
114+
},
115+
"properties": {
116+
"account": {"type": "string"},
117+
"detail": {"$ref": "#/definitions/AWSAPICallViaCloudTrail"},
118+
"detail-type": {"type": "string"},
119+
"id": {"type": "string"},
120+
"region": {"type": "string"},
121+
"resources": {"items": {"type": "string"}, "type": "array"},
122+
"source": {"type": "string"},
123+
"time": {"format": "date-time", "type": "string"},
124+
"version": {"type": "string"},
125+
},
126+
"required": ["detail-type", "resources", "id", "source", "time", "detail", "region", "version", "account"],
127+
"title": "AWSAPICallViaCloudTrail",
128+
"type": "object",
129+
"x-amazon-events-detail-type": "AWS API Call via CloudTrail",
130+
"x-amazon-events-source": "aws.s3",
131+
}

docs/index.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,7 @@ Core utilities such as Tracing, Logging, Metrics, and Event Handler will be avai
255255
As a best practice, AWS Lambda Powertools module logging statements are suppressed. If necessary, you can enable debugging using `set_package_logger` for additional information on every internal operation:
256256

257257
```python title="Powertools debug mode example"
258-
from aws_lambda_powertools.logging.logger import set_package_logger
259-
260-
set_package_logger() # (1)
258+
--8<-- "docs/examples/index/debug_mode.py"
261259
```
262260

263261
1. :information_source: this will configure our `aws_lambda_powertools` logger with debug.

docs/shared/validation_basic_jsonschema.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@
3333
"examples": [{"statusCode": 200, "body": "response"}],
3434
"required": ["statusCode", "body"],
3535
"properties": {
36-
"statusCode": {"$id": "#/properties/statusCode", "type": "integer", "title": "The statusCode"},
37-
"body": {"$id": "#/properties/body", "type": "string", "title": "The response"},
36+
"statusCode": {
37+
"$id": "#/properties/statusCode",
38+
"type": "integer",
39+
"title": "The statusCode",
40+
},
41+
"body": {
42+
"$id": "#/properties/body",
43+
"type": "string",
44+
"title": "The response",
45+
},
3846
},
3947
}

docs/utilities/batch.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,27 +533,27 @@ decorator or `PartialSQSProcessor` class.
533533
534534
=== "Decorator"
535535

536-
```python hl_lines="5 15"
536+
```python hl_lines="5 15"
537537
--8<-- "docs/examples/utilities/batch/custom_config_decorator.py"
538538
```
539539

540540
=== "Context manager"
541541

542-
```python hl_lines="5 18"
542+
```python hl_lines="5 18"
543543
--8<-- "docs/examples/utilities/batch/custom_config_context_manager.py"
544544
```
545545

546546
> Custom boto3 session example
547547
548548
=== "Decorator"
549549

550-
```python hl_lines="5 15"
550+
```python hl_lines="5 15"
551551
--8<-- "docs/examples/utilities/batch/custom_boto3_session_decorator.py"
552552
```
553553

554554
=== "Context manager"
555555

556-
```python hl_lines="5 18"
556+
```python hl_lines="5 18"
557557
--8<-- "docs/examples/utilities/batch/custom_boto3_session_context_manager.py"
558558
```
559559

docs/utilities/data_classes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ This example is based on the AWS Blog post [Introducing Amazon S3 Object Lambda
505505

506506
=== "app.py"
507507

508-
```python hl_lines="5-6 13 15"
508+
```python hl_lines="5-6 13 15"
509509
--8<-- "docs/examples/utilities/data_classes/app_s3_object_lambda.py"
510510
```
511511

docs/utilities/jmespath_functions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ This sample will decode the value within the `data` key into a valid JSON before
113113

114114
=== "schemas.py"
115115

116-
```python hl_lines="7 14 16 23 39 45 47 52"
116+
```python hl_lines="8 10 17 23 34 36 41"
117117
--8<-- "docs/shared/validation_basic_jsonschema.py"
118118
```
119119

@@ -139,7 +139,7 @@ This sample will decode the base64 value within the `data` key, and decode the J
139139

140140
=== "schemas.py"
141141

142-
```python hl_lines="7 14 16 23 39 45 47 52"
142+
```python hl_lines="8 10 17 23 34 36 41"
143143
--8<-- "docs/shared/validation_basic_jsonschema.py"
144144
```
145145

@@ -157,7 +157,7 @@ This sample will decompress and decode base64 data, then use JMESPath pipeline e
157157

158158
=== "schemas.py"
159159

160-
```python hl_lines="7 14 16 23 39 45 47 52"
160+
```python hl_lines="8 10 17 23 34 36 41"
161161
--8<-- "docs/shared/validation_basic_jsonschema.py"
162162
```
163163

0 commit comments

Comments
 (0)