Skip to content

Commit 68c8562

Browse files
docs(examples): standardize lambda handler function name (#2192)
1 parent b9b3933 commit 68c8562

39 files changed

+39
-39
lines changed

examples/logger/sam/template.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Description: AWS Lambda Powertools Tracer doc examples
55
Globals:
66
Function:
77
Timeout: 5
8-
Runtime: python3.9
8+
Runtime: python3.10
99
Tracing: Active
1010
Environment:
1111
Variables:

examples/logger/src/append_keys.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
logger = Logger()
55

66

7-
def handler(event: dict, context: LambdaContext) -> str:
7+
def lambda_handler(event: dict, context: LambdaContext) -> str:
88
order_id = event.get("order_id")
99

1010
# this will ensure order_id key always has the latest value before logging

examples/logger/src/append_keys_extra.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
logger = Logger()
55

66

7-
def handler(event: dict, context: LambdaContext) -> str:
7+
def lambda_handler(event: dict, context: LambdaContext) -> str:
88
fields = {"request_id": "1123"}
99
logger.info("Collecting payment", extra=fields)
1010

examples/logger/src/append_keys_kwargs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
logger = Logger()
55

66

7-
def handler(event: dict, context: LambdaContext) -> str:
7+
def lambda_handler(event: dict, context: LambdaContext) -> str:
88
logger.info("Collecting payment", request_id="1123")
99

1010
return "hello world"

examples/logger/src/append_keys_vs_extra.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class PaymentError(Exception):
1212
...
1313

1414

15-
def handler(event, context):
15+
def lambda_handler(event, context):
1616
logger.append_keys(payment_id="123456789")
1717
charge_id = event.get("charge_id", "")
1818

examples/logger/src/bring_your_own_formatter_from_scratch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ def format(self, record: logging.LogRecord) -> str: # noqa: A003
3939

4040

4141
@logger.inject_lambda_context
42-
def handler(event, context):
42+
def lambda_handler(event, context):
4343
logger.info("Collecting payment")

examples/logger/src/clear_state.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
@logger.inject_lambda_context(clear_state=True)
8-
def handler(event: dict, context: LambdaContext) -> str:
8+
def lambda_handler(event: dict, context: LambdaContext) -> str:
99
if event.get("special_key"):
1010
# Should only be available in the first request log
1111
# as the second request doesn't contain `special_key`

examples/logger/src/enabling_boto_logging.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
client = boto3.client("s3")
1313

1414

15-
def handler(event: Dict, context: LambdaContext) -> List:
15+
def lambda_handler(event: Dict, context: LambdaContext) -> List:
1616
response = client.list_buckets()
1717

1818
return response.get("Buckets", [])

examples/logger/src/fake_lambda_context_for_logger_module.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
@logger.inject_lambda_context
8-
def handler(event: dict, context: LambdaContext) -> str:
8+
def lambda_handler(event: dict, context: LambdaContext) -> str:
99
logger.info("Collecting payment")
1010

1111
return "hello world"

examples/logger/src/inject_lambda_context.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
@logger.inject_lambda_context
8-
def handler(event: dict, context: LambdaContext) -> str:
8+
def lambda_handler(event: dict, context: LambdaContext) -> str:
99
logger.info("Collecting payment")
1010

1111
# You can log entire objects too

examples/logger/src/log_incoming_event.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66

77
@logger.inject_lambda_context(log_event=True)
8-
def handler(event: dict, context: LambdaContext) -> str:
8+
def lambda_handler(event: dict, context: LambdaContext) -> str:
99
return "hello world"

examples/logger/src/logger_reuse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
@logger.inject_lambda_context
10-
def handler(event: dict, context: LambdaContext) -> str:
10+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1111
inject_payment_id(context=event)
1212
logger.info("Collecting payment")
1313
return "hello world"

examples/logger/src/logging_exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
logger = Logger()
88

99

10-
def handler(event: dict, context: LambdaContext) -> str:
10+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1111
try:
1212
ret = requests.get(ENDPOINT)
1313
ret.raise_for_status()

examples/logger/src/logging_inheritance_bad.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
@logger.inject_lambda_context
13-
def handler(event: dict, context: LambdaContext) -> str:
13+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1414
inject_payment_id(context=event)
1515

1616
return "hello world"

examples/logger/src/logging_inheritance_good.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
@logger.inject_lambda_context
13-
def handler(event: dict, context: LambdaContext) -> str:
13+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1414
inject_payment_id(context=event)
1515

1616
return "hello world"

examples/logger/src/logging_uncaught_exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
logger = Logger(log_uncaught_exceptions=True)
88

99

10-
def handler(event: dict, context: LambdaContext) -> str:
10+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1111
ret = requests.get(ENDPOINT)
1212
# HTTP 4xx/5xx status will lead to requests.HTTPError
1313
# Logger will log this exception before this program exits non-successfully

examples/logger/src/remove_keys.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
logger = Logger()
55

66

7-
def handler(event: dict, context: LambdaContext) -> str:
7+
def lambda_handler(event: dict, context: LambdaContext) -> str:
88
logger.append_keys(sample_key="value")
99
logger.info("Collecting payment")
1010

examples/logger/src/sampling_debug_logs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
logger = Logger(service="payment", sample_rate=0.1)
77

88

9-
def handler(event: dict, context: LambdaContext):
9+
def lambda_handler(event: dict, context: LambdaContext):
1010
logger.debug("Verifying whether order_id is present")
1111
logger.info("Collecting payment")
1212

examples/logger/src/set_correlation_id.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
@logger.inject_lambda_context(correlation_id_path="headers.my_request_id_header")
8-
def handler(event: dict, context: LambdaContext) -> str:
8+
def lambda_handler(event: dict, context: LambdaContext) -> str:
99
logger.debug(f"Correlation ID => {logger.get_correlation_id()}")
1010
logger.info("Collecting payment")
1111

examples/logger/src/set_correlation_id_jmespath.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_REST)
9-
def handler(event: dict, context: LambdaContext) -> str:
9+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1010
logger.debug(f"Correlation ID => {logger.get_correlation_id()}")
1111
logger.info("Collecting payment")
1212

examples/logger/src/set_correlation_id_method.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
logger = Logger()
66

77

8-
def handler(event: dict, context: LambdaContext) -> str:
8+
def lambda_handler(event: dict, context: LambdaContext) -> str:
99
request = APIGatewayProxyEvent(event)
1010

1111
logger.set_correlation_id(request.request_context.request_id)

examples/metrics/sam/template.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Description: AWS Lambda Powertools Metrics doc examples
55
Globals:
66
Function:
77
Timeout: 5
8-
Runtime: python3.9
8+
Runtime: python3.10
99
Tracing: Active
1010
Environment:
1111
Variables:

examples/tracer/sam/template.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Description: AWS Lambda Powertools Tracer doc examples
55
Globals:
66
Function:
77
Timeout: 5
8-
Runtime: python3.9
8+
Runtime: python3.10
99
Tracing: Active
1010
Environment:
1111
Variables:

examples/tracer/src/capture_lambda_handler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ def collect_payment(charge_id: str) -> str:
1010

1111

1212
@tracer.capture_lambda_handler
13-
def handler(event: dict, context: LambdaContext) -> str:
13+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1414
charge_id = event.get("charge_id", "")
1515
return collect_payment(charge_id=charge_id)

examples/tracer/src/capture_method.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ def collect_payment(charge_id: str) -> str:
1111

1212

1313
@tracer.capture_lambda_handler
14-
def handler(event: dict, context: LambdaContext) -> str:
14+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1515
charge_id = event.get("charge_id", "")
1616
return collect_payment(charge_id=charge_id)

examples/tracer/src/capture_method_async.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ async def collect_payment(charge_id: str) -> str:
1414

1515

1616
@tracer.capture_lambda_handler
17-
def handler(event: dict, context: LambdaContext) -> str:
17+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1818
charge_id = event.get("charge_id", "")
1919
return asyncio.run(collect_payment(charge_id=charge_id))

examples/tracer/src/capture_method_async_concurrency.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ async def collect_payment(charge_id: str) -> str:
2626

2727

2828
@tracer.capture_lambda_handler
29-
def handler(event: dict, context: LambdaContext) -> str:
29+
def lambda_handler(event: dict, context: LambdaContext) -> str:
3030
charge_id = event.get("charge_id", "")
3131
return asyncio.run(collect_payment(charge_id=charge_id))

examples/tracer/src/capture_method_context_manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def collect_payment(charge_id: str) -> Generator[str, None, None]:
1919

2020
@tracer.capture_lambda_handler
2121
@logger.inject_lambda_context
22-
def handler(event: dict, context: LambdaContext) -> str:
22+
def lambda_handler(event: dict, context: LambdaContext) -> str:
2323
charge_id = event.get("charge_id", "")
2424
with collect_payment(charge_id=charge_id) as receipt_id:
2525
logger.info(f"Processing payment collection for charge {charge_id} with receipt {receipt_id}")

examples/tracer/src/capture_method_generators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ def collect_payment(charge_id: str) -> Generator[str, None, None]:
1212

1313

1414
@tracer.capture_lambda_handler
15-
def handler(event: dict, context: LambdaContext) -> str:
15+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1616
charge_id = event.get("charge_id", "")
1717
return next(collect_payment(charge_id=charge_id))

examples/tracer/src/disable_capture_error.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def collect_payment(charge_id: str) -> dict:
2424

2525

2626
@tracer.capture_lambda_handler(capture_error=False)
27-
def handler(event: dict, context: LambdaContext) -> str:
27+
def lambda_handler(event: dict, context: LambdaContext) -> str:
2828
charge_id = event.get("charge_id", "")
2929
ret = collect_payment(charge_id=charge_id)
3030

examples/tracer/src/disable_capture_response.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ def collect_payment(charge_id: str) -> str:
1313

1414

1515
@tracer.capture_lambda_handler(capture_response=False)
16-
def handler(event: dict, context: LambdaContext) -> str:
16+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1717
charge_id = event.get("charge_id", "")
1818
return collect_payment(charge_id=charge_id)

examples/tracer/src/disable_capture_response_streaming_body.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def fetch_payment_report(payment_id: str) -> StreamingBody:
2424

2525

2626
@tracer.capture_lambda_handler(capture_response=False)
27-
def handler(event: dict, context: LambdaContext) -> str:
27+
def lambda_handler(event: dict, context: LambdaContext) -> str:
2828
payment_id = event.get("payment_id", "")
2929
report = fetch_payment_report(payment_id=payment_id)
3030
return report.read().decode()

examples/tracer/src/ignore_endpoints.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def collect_payment(charge_id: str) -> dict:
2828

2929

3030
@tracer.capture_lambda_handler(capture_error=False)
31-
def handler(event: dict, context: LambdaContext) -> str:
31+
def lambda_handler(event: dict, context: LambdaContext) -> str:
3232
charge_id = event.get("charge_id", "")
3333
ret = collect_payment(charge_id=charge_id)
3434

examples/tracer/src/patch_modules.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
@tracer.capture_lambda_handler
12-
def handler(event: dict, context: LambdaContext) -> str:
12+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1313
ret = requests.get("https://httpbin.org/get")
1414
ret.raise_for_status()
1515

examples/tracer/src/put_trace_annotations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ def collect_payment(charge_id: str) -> str:
1010

1111

1212
@tracer.capture_lambda_handler
13-
def handler(event: dict, context: LambdaContext) -> str:
13+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1414
charge_id = event.get("charge_id", "")
1515
return collect_payment(charge_id=charge_id)

examples/tracer/src/put_trace_metadata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def collect_payment(charge_id: str) -> str:
99

1010

1111
@tracer.capture_lambda_handler
12-
def handler(event: dict, context: LambdaContext) -> str:
12+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1313
payment_context = {
1414
"charge_id": event.get("charge_id", ""),
1515
"merchant_id": event.get("merchant_id", ""),

examples/tracer/src/sdk_escape_hatch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def collect_payment(charge_id: str) -> str:
99

1010

1111
@tracer.capture_lambda_handler
12-
def handler(event: dict, context: LambdaContext) -> str:
12+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1313
charge_id = event.get("charge_id", "")
1414
with tracer.provider.in_subsegment("## collect_payment") as subsegment:
1515
subsegment.put_annotation(key="PaymentId", value=charge_id)

examples/tracer/src/tracer_reuse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88

99
@tracer.capture_lambda_handler
10-
def handler(event: dict, context: LambdaContext) -> str:
10+
def lambda_handler(event: dict, context: LambdaContext) -> str:
1111
charge_id = event.get("charge_id", "")
1212
return collect_payment(charge_id=charge_id)

examples/tracer/src/tracing_aiohttp.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ async def collect_payment(charge_id: str) -> dict:
2020

2121

2222
@tracer.capture_lambda_handler
23-
def handler(event: dict, context: LambdaContext) -> dict:
23+
def lambda_handler(event: dict, context: LambdaContext) -> dict:
2424
charge_id = event.get("charge_id", "")
2525
return asyncio.run(collect_payment(charge_id=charge_id))

0 commit comments

Comments
 (0)