Skip to content

Commit 5729b6d

Browse files
committed
chore: bump example to use 0.8.0 features
1 parent a99e647 commit 5729b6d

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

Diff for: python/example/hello_world/app.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
import requests
44

5-
from aws_lambda_powertools.logging import logger_inject_lambda_context, logger_setup
5+
from aws_lambda_powertools.logging import Logger
66
from aws_lambda_powertools.metrics import Metrics, MetricUnit, single_metric
77
from aws_lambda_powertools.middleware_factory import lambda_handler_decorator
88
from aws_lambda_powertools.tracing import Tracer
9+
from aws_lambda_powertools.logging.logger import set_package_logger
10+
11+
set_package_logger() # Enable package diagnostics (DEBUG log)
912

1013
tracer = Tracer()
11-
logger = logger_setup()
14+
logger = Logger()
1215
metrics = Metrics()
1316

1417
_cold_start = True
@@ -31,7 +34,7 @@ def my_middleware(handler, event, context, say_hello=False):
3134
@metrics.log_metrics
3235
@tracer.capture_lambda_handler
3336
@my_middleware(say_hello=True)
34-
@logger_inject_lambda_context
37+
@logger.inject_lambda_context
3538
def lambda_handler(event, context):
3639
"""Sample pure Lambda function
3740
@@ -53,6 +56,9 @@ def lambda_handler(event, context):
5356
5457
Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
5558
"""
59+
if "charge_id" in event:
60+
logger.structure_logs(append=True, payment_id="charge_id")
61+
5662
global _cold_start
5763
if _cold_start:
5864
logger.debug("Recording cold start metric")

Diff for: python/example/template.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Resources:
2424
POWERTOOLS_TRACE_DISABLED: "false" # Explicitly disables tracing
2525
POWERTOOLS_LOGGER_LOG_EVENT: "false" # Logs incoming event
2626
POWERTOOLS_LOGGER_SAMPLE_RATE: "0" # Debug log sampling percentage
27-
POWERTOOLS_METRICS_NAMESPACE: "Example" # Debug log sampling percentage
28-
LOG_LEVEL: INFO # Log level (INFO, DEBUG, etc.)
27+
POWERTOOLS_METRICS_NAMESPACE: "Example" # Metric Namespace
28+
LOG_LEVEL: INFO # Log level (INFO, DEBUG, etc.)
2929
Events:
3030
HelloWorld:
3131
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api

0 commit comments

Comments
 (0)