def search_things()

in source/tools/iot-search-devices.py [0:0]


def search_things(max_results):
    global NUM_THINGS
    logger.info('args.query_string: {} max_results: {}'.format(args.query_string, max_results))
    try:
        session = boto3.Session()
        region = session.region_name
        c_iot = session.client('iot')
        response = c_iot.search_index(
            indexName='AWS_Things',
            queryString=args.query_string,
            maxResults=max_results
        )

        for thing in response['things']:
            logger.info('region: {} thing: {}'.format(region, thing))
            NUM_THINGS += 1

        next_token = get_next_token(response)

        while next_token:
            session = boto3.Session()
            region = session.region_name
            c_iot = session.client('iot')
            response = c_iot.search_index(
                indexName='AWS_Things',
                nextToken=next_token,
                queryString=args.query_string,
                maxResults=max_results
            )
            next_token = get_next_token(response)

            for thing in response['things']:
                logger.info('region: {} thing: {}'.format(region, thing))
                NUM_THINGS += 1
                
    except Exception as e:
        logger.error('{}'.format(e))