def lambda_handler()

in src/backend/booking/src/notify-booking/notify.py [0:0]


def lambda_handler(event, context):
    """AWS Lambda Function entrypoint to notify booking

    Parameters
    ----------
    event: dict, required
        Step Functions State Machine event

        customer_id: string
            Unique Customer ID

        price: string
            Flight price

        bookingReference: string
            Confirmed booking reference

    context: object, required
        Lambda Context runtime methods and attributes
        Context doc: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html

    Returns
    -------
    string
        notificationId
            Unique ID confirming notification delivery

    Raises
    ------
    BookingNotificationException
        Booking Notification Exception including error message upon failure
    """
    customer_id = event.get("customerId", False)
    payment = event.get("payment", {})
    price = payment.get("price", False)
    booking_reference = event.get("bookingReference", False)

    if not customer_id and not price:
        metrics.add_metric(name="InvalidNotificationRequest", unit=MetricUnit.Count, value=1)
        logger.error({"operation": "input_validation", "details": event})
        raise ValueError("Invalid customer and price")

    try:
        payload = {"customerId": customer_id, "price": price}
        ret = notify_booking(payload, booking_reference)

        metrics.add_metric(name="SuccessfulNotification", unit=MetricUnit.Count, value=1)
        tracer.put_annotation("BookingNotification", ret["notificationId"])
        tracer.put_annotation("BookingNotificationStatus", "SUCCESS")

        # Step Functions use the return to append `notificationId` key into the overall output
        return ret["notificationId"]
    except BookingNotificationException as err:
        metrics.add_metric(name="FailedNotification", unit=MetricUnit.Count, value=1)
        tracer.put_annotation("BookingNotificationStatus", "FAILED")
        logger.exception({"operation": "booking_notification"})
        raise