def handler()

in orders/src/get_order/main.py [0:0]


def handler(event, _):
    """
    Lambda function handler for GetOrder
    """

    logger.debug({"message": "Event received", "event": event})

    # Retrieve the userId
    user_id = iam_user_id(event)
    if user_id is not None:
        logger.info({"message": "Received get order from IAM user", "userArn": user_id})
        tracer.put_annotation("userArn", user_id)
        tracer.put_annotation("iamUser", True)
        iam_user = True
    else:
        logger.warning({"message": "User ID not found in event"})
        return response("Unauthorized", 401)

    # Retrieve the orderId
    try:
        order_id = event["pathParameters"]["orderId"]
    except (KeyError, TypeError):
        logger.warning({"message": "Order ID not found in event"})
        return response("Missing orderId", 400)

    # Set a trace annotation
    tracer.put_annotation("orderId", order_id)

    # Retrieve the order from DynamoDB
    order = get_order(order_id)

    # Check that the order can be sent to the user
    # This includes both when the item is not found and when the user IDs do
    # not match.
    if order is None or (not iam_user and user_id != order["userId"]):
        return response("Order not found", 404)

    # Send the response
    return response(order)