def get_email_from_user(user):
    """Get email address for user returned by cognito or database."""
    key = "UserAttributes" if "UserAttributes" in user else "Attributes"
    return next(filter(lambda x: x["Name"] == "email", user[key]), {}).get("Value")