forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(docs): Extract middleware examples
Changes: - Extract code examples - Run isort and black - Update line highlights - Add make task Related to: - aws-powertools#1064
- Loading branch information
1 parent
b577366
commit 37ae639
Showing
6 changed files
with
69 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
docs/examples/utilities/middleware_factory/middleware_no_params.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from aws_lambda_powertools.middleware_factory import lambda_handler_decorator | ||
|
||
|
||
@lambda_handler_decorator | ||
def middleware_before_after(handler, event, context): | ||
# logic_before_handler_execution() | ||
response = handler(event, context) | ||
# logic_after_handler_execution() | ||
return response | ||
|
||
|
||
@middleware_before_after | ||
def lambda_handler(event, context): | ||
... |
10 changes: 10 additions & 0 deletions
10
docs/examples/utilities/middleware_factory/middleware_trace_custom.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from aws_lambda_powertools import Tracer | ||
from aws_lambda_powertools.middleware_factory import lambda_handler_decorator | ||
|
||
|
||
@lambda_handler_decorator(trace_execution=True) | ||
def middleware_name(handler, event, context): | ||
# tracer = Tracer() # Takes a copy of an existing tracer instance | ||
# tracer.add_annotation... | ||
# tracer.add_metadata... | ||
return handler(event, context) |
11 changes: 11 additions & 0 deletions
11
docs/examples/utilities/middleware_factory/middleware_trace_execution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from aws_lambda_powertools.middleware_factory import lambda_handler_decorator | ||
|
||
|
||
@lambda_handler_decorator(trace_execution=True) | ||
def my_middleware(handler, event, context): | ||
return handler(event, context) | ||
|
||
|
||
@my_middleware | ||
def lambda_handler(event, context): | ||
... |
19 changes: 19 additions & 0 deletions
19
docs/examples/utilities/middleware_factory/middleware_with_params.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from typing import List | ||
|
||
from aws_lambda_powertools.middleware_factory import lambda_handler_decorator | ||
|
||
|
||
@lambda_handler_decorator | ||
def obfuscate_sensitive_data(handler, event, context, fields: List = None): | ||
# Obfuscate email before calling Lambda handler | ||
if fields: | ||
for field in fields: | ||
if field in event: | ||
event[field] = obfuscate(event[field]) | ||
|
||
return handler(event, context) | ||
|
||
|
||
@obfuscate_sensitive_data(fields=["email"]) | ||
def lambda_handler(event, context): | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters