from typing import Any, Mapping
import json

from utils.logger import setup_logger

logger = setup_logger()


def handler(event: Mapping[str, Any], context: Any) -> None:
    logger.info("Received event:")

    for record in event.get("Records", []):
        body_str = record.get("body", "")

        try:
            body_obj = json.loads(body_str)
        except json.JSONDecodeError:
            logger.error("Failed to parse body as JSON")
            logger.info(body_str)
            continue

        logger.info("Parsed message body:")
        logger.info(json.dumps(body_obj, indent=2))
