Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(examples): standardize lambda handler function name #2192

Merged
merged 2 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/logger/sam/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Description: AWS Lambda Powertools Tracer doc examples
Globals:
Function:
Timeout: 5
Runtime: python3.9
Runtime: python3.10
Tracing: Active
Environment:
Variables:
Expand Down
2 changes: 1 addition & 1 deletion examples/logger/src/append_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
logger = Logger()


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

# this will ensure order_id key always has the latest value before logging
Expand Down
2 changes: 1 addition & 1 deletion examples/logger/src/append_keys_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
logger = Logger()


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

Expand Down
2 changes: 1 addition & 1 deletion examples/logger/src/append_keys_kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
logger = Logger()


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

return "hello world"
2 changes: 1 addition & 1 deletion examples/logger/src/append_keys_vs_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PaymentError(Exception):
...


def handler(event, context):
def lambda_handler(event, context):
logger.append_keys(payment_id="123456789")
charge_id = event.get("charge_id", "")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ def format(self, record: logging.LogRecord) -> str: # noqa: A003


@logger.inject_lambda_context
def handler(event, context):
def lambda_handler(event, context):
logger.info("Collecting payment")
2 changes: 1 addition & 1 deletion examples/logger/src/clear_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


@logger.inject_lambda_context(clear_state=True)
def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
if event.get("special_key"):
# Should only be available in the first request log
# as the second request doesn't contain `special_key`
Expand Down
2 changes: 1 addition & 1 deletion examples/logger/src/enabling_boto_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
client = boto3.client("s3")


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

return response.get("Buckets", [])
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


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

return "hello world"
2 changes: 1 addition & 1 deletion examples/logger/src/inject_lambda_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


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

# You can log entire objects too
Expand Down
2 changes: 1 addition & 1 deletion examples/logger/src/log_incoming_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@


@logger.inject_lambda_context(log_event=True)
def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
return "hello world"
2 changes: 1 addition & 1 deletion examples/logger/src/logger_reuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@logger.inject_lambda_context
def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
inject_payment_id(context=event)
logger.info("Collecting payment")
return "hello world"
2 changes: 1 addition & 1 deletion examples/logger/src/logging_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
logger = Logger()


def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
try:
ret = requests.get(ENDPOINT)
ret.raise_for_status()
Expand Down
2 changes: 1 addition & 1 deletion examples/logger/src/logging_inheritance_bad.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


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

return "hello world"
2 changes: 1 addition & 1 deletion examples/logger/src/logging_inheritance_good.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


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

return "hello world"
2 changes: 1 addition & 1 deletion examples/logger/src/logging_uncaught_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
logger = Logger(log_uncaught_exceptions=True)


def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
ret = requests.get(ENDPOINT)
# HTTP 4xx/5xx status will lead to requests.HTTPError
# Logger will log this exception before this program exits non-successfully
Expand Down
2 changes: 1 addition & 1 deletion examples/logger/src/remove_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
logger = Logger()


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

Expand Down
2 changes: 1 addition & 1 deletion examples/logger/src/sampling_debug_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
logger = Logger(service="payment", sample_rate=0.1)


def handler(event: dict, context: LambdaContext):
def lambda_handler(event: dict, context: LambdaContext):
logger.debug("Verifying whether order_id is present")
logger.info("Collecting payment")

Expand Down
2 changes: 1 addition & 1 deletion examples/logger/src/set_correlation_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


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

Expand Down
2 changes: 1 addition & 1 deletion examples/logger/src/set_correlation_id_jmespath.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


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

Expand Down
2 changes: 1 addition & 1 deletion examples/logger/src/set_correlation_id_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
logger = Logger()


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

logger.set_correlation_id(request.request_context.request_id)
Expand Down
2 changes: 1 addition & 1 deletion examples/metrics/sam/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Description: AWS Lambda Powertools Metrics doc examples
Globals:
Function:
Timeout: 5
Runtime: python3.9
Runtime: python3.10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for that attention to detail!! <3

Tracing: Active
Environment:
Variables:
Expand Down
2 changes: 1 addition & 1 deletion examples/tracer/sam/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Description: AWS Lambda Powertools Tracer doc examples
Globals:
Function:
Timeout: 5
Runtime: python3.9
Runtime: python3.10
Tracing: Active
Environment:
Variables:
Expand Down
2 changes: 1 addition & 1 deletion examples/tracer/src/capture_lambda_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def collect_payment(charge_id: str) -> str:


@tracer.capture_lambda_handler
def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
charge_id = event.get("charge_id", "")
return collect_payment(charge_id=charge_id)
2 changes: 1 addition & 1 deletion examples/tracer/src/capture_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ def collect_payment(charge_id: str) -> str:


@tracer.capture_lambda_handler
def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
charge_id = event.get("charge_id", "")
return collect_payment(charge_id=charge_id)
2 changes: 1 addition & 1 deletion examples/tracer/src/capture_method_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ async def collect_payment(charge_id: str) -> str:


@tracer.capture_lambda_handler
def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
charge_id = event.get("charge_id", "")
return asyncio.run(collect_payment(charge_id=charge_id))
2 changes: 1 addition & 1 deletion examples/tracer/src/capture_method_async_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ async def collect_payment(charge_id: str) -> str:


@tracer.capture_lambda_handler
def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
charge_id = event.get("charge_id", "")
return asyncio.run(collect_payment(charge_id=charge_id))
2 changes: 1 addition & 1 deletion examples/tracer/src/capture_method_context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def collect_payment(charge_id: str) -> Generator[str, None, None]:

@tracer.capture_lambda_handler
@logger.inject_lambda_context
def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
charge_id = event.get("charge_id", "")
with collect_payment(charge_id=charge_id) as receipt_id:
logger.info(f"Processing payment collection for charge {charge_id} with receipt {receipt_id}")
Expand Down
2 changes: 1 addition & 1 deletion examples/tracer/src/capture_method_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ def collect_payment(charge_id: str) -> Generator[str, None, None]:


@tracer.capture_lambda_handler
def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
charge_id = event.get("charge_id", "")
return next(collect_payment(charge_id=charge_id))
2 changes: 1 addition & 1 deletion examples/tracer/src/disable_capture_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def collect_payment(charge_id: str) -> dict:


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

Expand Down
2 changes: 1 addition & 1 deletion examples/tracer/src/disable_capture_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ def collect_payment(charge_id: str) -> str:


@tracer.capture_lambda_handler(capture_response=False)
def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
charge_id = event.get("charge_id", "")
return collect_payment(charge_id=charge_id)
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def fetch_payment_report(payment_id: str) -> StreamingBody:


@tracer.capture_lambda_handler(capture_response=False)
def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
payment_id = event.get("payment_id", "")
report = fetch_payment_report(payment_id=payment_id)
return report.read().decode()
2 changes: 1 addition & 1 deletion examples/tracer/src/ignore_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def collect_payment(charge_id: str) -> dict:


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

Expand Down
2 changes: 1 addition & 1 deletion examples/tracer/src/patch_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


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

Expand Down
2 changes: 1 addition & 1 deletion examples/tracer/src/put_trace_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def collect_payment(charge_id: str) -> str:


@tracer.capture_lambda_handler
def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
charge_id = event.get("charge_id", "")
return collect_payment(charge_id=charge_id)
2 changes: 1 addition & 1 deletion examples/tracer/src/put_trace_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def collect_payment(charge_id: str) -> str:


@tracer.capture_lambda_handler
def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
payment_context = {
"charge_id": event.get("charge_id", ""),
"merchant_id": event.get("merchant_id", ""),
Expand Down
2 changes: 1 addition & 1 deletion examples/tracer/src/sdk_escape_hatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def collect_payment(charge_id: str) -> str:


@tracer.capture_lambda_handler
def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
charge_id = event.get("charge_id", "")
with tracer.provider.in_subsegment("## collect_payment") as subsegment:
subsegment.put_annotation(key="PaymentId", value=charge_id)
Expand Down
2 changes: 1 addition & 1 deletion examples/tracer/src/tracer_reuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@


@tracer.capture_lambda_handler
def handler(event: dict, context: LambdaContext) -> str:
def lambda_handler(event: dict, context: LambdaContext) -> str:
charge_id = event.get("charge_id", "")
return collect_payment(charge_id=charge_id)
2 changes: 1 addition & 1 deletion examples/tracer/src/tracing_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ async def collect_payment(charge_id: str) -> dict:


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