def handler()

in delivery-pricing/src/pricing/main.py [0:0]


def handler(event, _):
    """
    Lambda function handler for /backend/pricing
    """

    # Verify that this is a request with IAM credentials
    if iam_user_id(event) is None:
        logger.warning({"message": "User ARN not found in event"})
        return response("Unauthorized", 403)

    # Extract the request body
    try:
        body = json.loads(event["body"])
    except Exception as exc: # pylint: disable=broad-except
        logger.warning("Exception caught: %s", exc)
        return response("Failed to parse JSON body", 400)

    for key in ["products", "address"]:
        if key not in body:
            logger.info({
                "message": "Missing '{}' in body".format(key),
                "body": body
            })
            return response("Missing '{}' in body".format(key), 400)

    # Calculate the delivery pricing
    pricing = get_pricing(body["products"], body["address"])
    logger.debug({
        "message": "Estimated delivery pricing to {}".format(pricing),
        "pricing": pricing
    })

    # Send the response back
    return response({
        "pricing": pricing
    })