import time


def get_creds_with_retry(session, max_tries=10, sleep=0.1):
    """ Attempt to obtain credentials upto `max_tries` times with back off
    :param session: botocore session, see get_boto_session
    :param max_tries: number of attempt before failing and returing None
    """
    for i in range(max_tries):
        if i > 0:
            time.sleep(sleep)
            sleep = min(sleep*2, 10)

        creds = session.get_credentials()
        if creds is not None:
            return creds

    return None