Skip to content

Commit 437ec9e

Browse files
author
Michael Brewer
authored
docs: Correct code examples (#317)
* docs: Correct code examples Changes: * Fix formatting for the api docs * Correct the data classes code examples in the docs * docs: Fix typo for sampling rate
1 parent 6c31cc6 commit 437ec9e

File tree

8 files changed

+28
-17
lines changed

8 files changed

+28
-17
lines changed

Diff for: aws_lambda_powertools/logging/logger.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Logger(logging.Logger): # lgtm [py/missing-call-to-init]
5353
LOG_LEVEL: str
5454
logging level (e.g. INFO, DEBUG)
5555
POWERTOOLS_LOGGER_SAMPLE_RATE: float
56-
samping rate ranging from 0 to 1, 1 being 100% sampling
56+
sampling rate ranging from 0 to 1, 1 being 100% sampling
5757
5858
Parameters
5959
----------
-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
class MiddlewareInvalidArgumentError(Exception):
22
"""When middleware receives non keyword=arguments"""
3-
4-
pass

Diff for: aws_lambda_powertools/utilities/batch/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def batch_processor(
125125
Examples
126126
--------
127127
**Processes Lambda's event with PartialSQSProcessor**
128+
128129
>>> from aws_lambda_powertools.utilities.batch import batch_processor, PartialSQSProcessor
129130
>>>
130131
>>> def record_handler(record):

Diff for: aws_lambda_powertools/utilities/batch/sqs.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class PartialSQSProcessor(BasePartialProcessor):
5353
>>> # have been deleted from the queue after context's exit.
5454
>>>
5555
>>> return result
56+
5657
"""
5758

5859
def __init__(self, config: Optional[Config] = None, suppress_exception: bool = False):
@@ -163,10 +164,11 @@ def sqs_batch_processor(
163164
Examples
164165
--------
165166
**Processes Lambda's event with PartialSQSProcessor**
167+
166168
>>> from aws_lambda_powertools.utilities.batch import sqs_batch_processor
167169
>>>
168170
>>> def record_handler(record):
169-
>>> return record["body"]
171+
>>> return record["body"]
170172
>>>
171173
>>> @sqs_batch_processor(record_handler=record_handler)
172174
>>> def handler(event, context):

Diff for: aws_lambda_powertools/utilities/idempotency/idempotency.py

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def idempotent(
5151
Examples
5252
--------
5353
**Processes Lambda's event in an idempotent manner**
54+
5455
>>> from aws_lambda_powertools.utilities.idempotency import (
5556
>>> idempotent, DynamoDBPersistenceLayer, IdempotencyConfig
5657
>>> )

Diff for: aws_lambda_powertools/utilities/idempotency/persistence/dynamodb.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ def __init__(
5353
Examples
5454
--------
5555
**Create a DynamoDB persistence layer with custom settings**
56-
>>> from aws_lambda_powertools.utilities.idempotency import idempotent, DynamoDBPersistenceLayer
56+
57+
>>> from aws_lambda_powertools.utilities.idempotency import (
58+
>>> idempotent, DynamoDBPersistenceLayer
59+
>>> )
5760
>>>
5861
>>> persistence_store = DynamoDBPersistenceLayer(table_name="idempotency_store")
5962
>>>
60-
>>> @idempotent(persistence_store=persistence_store, event_key="body")
63+
>>> @idempotent(persistence_store=persistence_store)
6164
>>> def handler(event, context):
6265
>>> return {"StatusCode": 200}
6366
"""

Diff for: docs/utilities/data_classes.md

+16-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ For example, if your Lambda function is being triggered by an API Gateway proxy
3434
def lambda_handler(event, context):
3535
event: APIGatewayProxyEvent = APIGatewayProxyEvent(event)
3636

37-
if 'helloworld' in event.path && event.http_method == 'GET':
37+
if 'helloworld' in event.path and event.http_method == 'GET':
3838
do_something_with(event.body, user)
3939
```
4040

@@ -80,7 +80,7 @@ Typically used for API Gateway REST API or HTTP API using v1 proxy event.
8080
request_context = event.request_context
8181
identity = request_context.identity
8282

83-
if 'helloworld' in event.path && event.http_method == 'GET':
83+
if 'helloworld' in event.path and event.http_method == 'GET':
8484
user = identity.user
8585
do_something_with(event.body, user)
8686
```
@@ -97,7 +97,7 @@ Typically used for API Gateway REST API or HTTP API using v1 proxy event.
9797
request_context = event.request_context
9898
query_string_parameters = event.query_string_parameters
9999

100-
if 'helloworld' in event.raw_path && request_context.http.method == 'POST':
100+
if 'helloworld' in event.raw_path and request_context.http.method == 'POST':
101101
do_something_with(event.body, query_string_parameters)
102102
```
103103

@@ -110,11 +110,12 @@ decompress and parse json data from the event.
110110

111111
```python
112112
from aws_lambda_powertools.utilities.data_classes import CloudWatchLogsEvent
113+
from aws_lambda_powertools.utilities.data_classes.cloud_watch_logs_event import CloudWatchLogsDecodedData
113114

114115
def lambda_handler(event, context):
115116
event: CloudWatchLogsEvent = CloudWatchLogsEvent(event)
116117

117-
decompressed_log = event.parse_logs_data
118+
decompressed_log: CloudWatchLogsDecodedData = event.parse_logs_data
118119
log_events = decompressed_log.log_events
119120
for event in log_events:
120121
do_something_with(event.timestamp, event.message)
@@ -146,7 +147,7 @@ Verify Auth Challenge | `data_classes.cognito_user_pool_event.VerifyAuthChalleng
146147
def lambda_handler(event, context):
147148
event: PostConfirmationTriggerEvent = PostConfirmationTriggerEvent(event)
148149

149-
user_attributes = user_attributes = event.request.user_attributes
150+
user_attributes = event.request.user_attributes
150151
do_something_with(user_attributes)
151152
```
152153

@@ -159,7 +160,10 @@ attributes values (`AttributeValue`), as well as enums for stream view type (`St
159160
=== "lambda_app.py"
160161

161162
```python
162-
from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import DynamoDBStreamEvent, DynamoDBRecordEventName
163+
from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import (
164+
DynamoDBStreamEvent,
165+
DynamoDBRecordEventName
166+
)
163167

164168
def lambda_handler(event, context):
165169
event: DynamoDBStreamEvent = DynamoDBStreamEvent(event)
@@ -194,14 +198,16 @@ or plain text, depending on the original payload.
194198
```python
195199
from aws_lambda_powertools.utilities.data_classes import KinesisStreamEvent
196200

201+
197202
def lambda_handler(event, context):
198203
event: KinesisStreamEvent = KinesisStreamEvent(event)
199-
200-
# if data was delivered as json
201-
data = event.data_as_text()
204+
kinesis_record = next(event.records).kinesis
202205

203206
# if data was delivered as text
204-
data = event.data_as_json()
207+
data = kinesis_record.data_as_text()
208+
209+
# if data was delivered as json
210+
data = kinesis_record.data_as_json()
205211

206212
do_something_with(data)
207213
```

Diff for: docs/utilities/idempotency.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ You can quickly start by initializing the `DynamoDBPersistenceLayer` class and u
9999
)
100100
...
101101
return {
102-
"payment_id": payment.id
102+
"payment_id": payment.id,
103103
"message": "success",
104104
"statusCode": 200,
105105
}

0 commit comments

Comments
 (0)