Skip to content

Commit

Permalink
fix: lambda logging
Browse files Browse the repository at this point in the history
  • Loading branch information
notdodo committed Sep 21, 2024
1 parent cdb3426 commit 3887043
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
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

0 comments on commit 3887043

Please sign in to comment.