import re


def is_transaction_expired_exception(e):
    """
    Checks if exception occurred for an expired transaction

    :type e: :py:class:`botocore.exceptions.ClientError`
    :param e: The ClientError caught.

    :rtype: bool
    :return: True if the exception denote that a transaction has expired. False otherwise.
    """
    is_invalid_session = e.response['Error']['Code'] == 'InvalidSessionException'

    if "Message" in e.response["Error"]:
        return is_invalid_session and re.search("Transaction .* has expired", e.response["Error"]["Message"])

    return False