import re


def _parse_s3_uri(s3_uri):
    """Parse an Amazon S3 URI into bucket and key entities

    Parameters
    ----------
    s3_uri : str
        The Amazon S3 URI

    Returns
    -------
    dict
        dict with keys "bucket" and "key"
    """
    # Parse s3_uri into bucket and key
    pattern = r"(s3:\/\/)?(?P<bucket>[^\/]*)\/(?P<key>.*)"
    m = re.match(pattern, s3_uri)
    if m is None:
        raise ValueError(
            f"s3_uri is not a valid URI. It should match the regex "
            f"pattern {pattern}. You provided {s3_uri}."
        )
    else:
        return m.groupdict()