from typing import Dict


def parse_user(detail: Dict) -> str:
    """
    Returns the closest match we can find to the user's identity from the event detail.
    :param detail: Event detail provided from SSM event.
    :return: UserId
    """
    principal_id = detail.get('userIdentity', {}).get('principalId')

    if ':' in principal_id:
        return principal_id.split(':')[1]
    else:
        return detail.get('userIdentity', {}).get('arn', 'arn/UnknownUser').split('/')[-1]