from typing import Optional


def cognito_user_id(event: dict) -> Optional[str]:
    """
    Returns the User ID (sub) from cognito or None
    """

    try:
        return event["requestContext"]["authorizer"]["claims"]["sub"]
    except (TypeError, KeyError):
        return None