in products/src/validate/main.py [0:0]
def handler(event, _):
"""
Lambda function handler for /backend/validate
"""
user_id = iam_user_id(event)
if user_id is None:
logger.warning({"message": "User ARN not found in event"})
return response("Unauthorized", 401)
# Extract the list of products
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)
if "products" not in body:
return response("Missing 'products' in body", 400)
products, reason = validate_products(body["products"])
if len(products) > 0:
return response({
"message": reason,
"products": products
}, 200)
return response("All products are valid")