def batch_stop_resources()

in cdk-project/lambda/python-functions/clean_endpoints.py [0:0]


def batch_stop_resources(client, before_timestamp, resource_type):
    try:
        next_token = None
        more = True
        while more:
            logger.info("Searching for %s from before: %s", resource_type.lower(), before_timestamp)
            resources, next_token = get_resources(
                client, next_token, before_timestamp, resource_type
            )
            logger.info("Found %s items, stopping now", len(resources))
            if resource_type == "MonitoringSchedules":
                resource_names = [resource["MonitoringScheduleName"] for resource in resources]
            elif resource_type == "ProcessingJobs":
                resource_names = [resource["ProcessingJobName"] for resource in resources]
            stopped = stop_resources(client, resource_names, resource_type)
            more = stopped and (next_token is not None)
            time.sleep(1)
    finally:
        logger.info(
            "Finished cleaning %s at %s", resource_type.lower(), str(datetime.datetime.now())
        )