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

fix: lambda logging #18

Merged
merged 1 commit into from
Sep 21, 2024
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 app/erfiume/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

from aws_lambda_powertools import Logger

logger = Logger(service="erfiume", level="INFO", child=True)
logger = Logger(service="erfiume")
4 changes: 2 additions & 2 deletions app/erfiume/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async def check_and_update_stazioni(self, station: Stazione) -> None:
# Get the latest timestamp from the DynamoDB response
latest_timestamp = (
int(response["Item"].get("timestamp")) # type: ignore[arg-type]
if response["Item"]
if "Item" in response
else 0
)

Expand Down Expand Up @@ -94,7 +94,7 @@ async def get_matching_station(self, station_name: str) -> Stazione | None:
Key={"nomestaz": station_name},
)

if stazione["Item"]:
if "Item" in stazione:
return Stazione(**stazione["Item"]) # type: ignore[arg-type]
logger.info("Station %s not found in DynamoDB.", station_name)
except ClientError as e:
Expand Down
5 changes: 3 additions & 2 deletions app/erfiume_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
from aws_lambda_powertools.utilities.typing import LambdaContext


@logger.inject_lambda_context
def handler(event: dict[str, Any], _context: LambdaContext) -> dict[str, Any]:
"""Run entry point for the bot."""
logger.info("Received event: %s", event)
try:
asyncio.run(bot(event))
except Exception as e: # noqa: BLE001
logger.error(f"An error occurred: {e!s}")
logger.error(traceback.format_exc())
logger.exception("An error occurred: %s", e)
logger.exception(traceback.format_exc())
return {"statusCode": 501}

logger.info("Successfully processed event")
Expand Down
1 change: 1 addition & 0 deletions app/erfiume_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async def main() -> None:
await update_task


@logger.inject_lambda_context
def handler(_event: dict[str, Any], _context: LambdaContext) -> None:
"""
AWS Lambda starting method
Expand Down
Loading