index traildbs directly from s3 for multiple accounts.

    context: assumes a daily traildb file in s3 with dated key path

def index(
        config, date=None, directory=None, concurrency=5, accounts=None,
        tag=None, verbose=False):
    """index traildbs directly from s3 for multiple accounts.

    context: assumes a daily traildb file in s3 with dated key path
    """

    logging.basicConfig(level=(verbose and logging.DEBUG or logging.INFO))
    logging.getLogger('botocore').setLevel(logging.WARNING)
    logging.getLogger('elasticsearch').setLevel(logging.WARNING)
    logging.getLogger('urllib3').setLevel(logging.WARNING)
    logging.getLogger('requests').setLevel(logging.WARNING)
    logging.getLogger('c7n.worker').setLevel(logging.INFO)

    with open(config) as fh:
        config = yaml.safe_load(fh.read())
    jsonschema.validate(config, CONFIG_SCHEMA)

    date = get_date_path(date, delta=24)
    directory = directory or "/tmp"

    with ProcessPoolExecutor(max_workers=concurrency) as w:
        futures = {}
        jobs = []

        for account in config.get('accounts'):
            if accounts and account['name'] not in accounts:
                continue
            if tag:
                found = False
                for t in account['tags'].values():
                    if tag == t:
                        found = True
                        break
                if not found:
                    continue
            for region in account.get('regions'):
                p = (config, account, region, date, directory)
                jobs.append(p)

        for j in jobs:
            log.debug("submit account:{} region:{} date:{}".format(
                j[1]['name'], j[2], j[3]))
            futures[w.submit(index_account_trails, *j)] = j

        # Process completed
        for f in as_completed(futures):
            config, account, region, date, directory = futures[f]
            if f.exception():
                log.warning("error account:{} region:{} error:{}".format(
                    account['name'], region, f.exception()))
                continue
            log.info("complete account:{} region:{}".format(
                account['name'], region))