(self, instance_ids: List[str], batch_size: int = 500)
return terminated_instance_ids
Terminate instances in this resource group

        :param instance_ids: a list of instance IDs to terminate
        :param batch_size: number of instances to terminate at one time
        :returns: a list of terminated instance IDs
Terminate instances in this resource group
Terminate instances in this resource group
def terminate_instances_by_id(self, instance_ids: List[str], batch_size: int = 500) -> Sequence[str]:
        """ Terminate instances in this resource group

        :param instance_ids: a list of instance IDs to terminate
        :param batch_size: number of instances to terminate at one time
        :returns: a list of terminated instance IDs
        """
        if not instance_ids:
            logger.warning(f"No instances to terminate in {self.group_id}")
            return []

        instance_weights = {}
        for instance in ec2_describe_instances(instance_ids):
            instance_market = get_instance_market(instance)
            if not instance_market.az:
                logger.warning(
                    f"Instance {instance['InstanceId']} missing AZ info, likely already terminated so skipping",
                )
                instance_ids.remove(instance["InstanceId"])
                continue
            instance_weights[instance["InstanceId"]] = self.market_weight(get_instance_market(instance))

        # AWS API recommends not terminating more than 1000 instances at a time, and to
        # terminate larger numbers in batches
        terminated_instance_ids = []
        for batch in range(0, len(instance_ids), batch_size):
            response = ec2.terminate_instances(InstanceIds=instance_ids[batch : batch + batch_size])
            terminated_instance_ids.extend([instance["InstanceId"] for instance in response["TerminatingInstances"]])

        # It's possible that not every instance is terminated.  The most likely cause for this
        # is that AWS terminated the instance in between getting its status and the terminate_instances
        # request.  This is probably fine but let's log a warning just in case.
        missing_instances = set(instance_ids) - set(terminated_instance_ids)
        if missing_instances:
            logger.warning("Some instances could not be terminated; they were probably killed previously")
            logger.warning(f"Missing instances: {list(missing_instances)}")
        terminated_capacity = sum(instance_weights[i] for i in instance_ids)

        logger.info(f"{self.id} terminated weight: {terminated_capacity}; instances: {terminated_instance_ids}")
        return terminated_instance_ids
def terminate_instances_by_id ( self , instance_ids : List [ str ] , batch_size : int = 500 ) -> Sequence [ str ] : if not instance_ids : logger . warning ( f"No instances to terminate in {self.group_id}" ) return [ ] instance_weights = { } for instance in ec2_describe_instances ( instance_ids ) : instance_market = get_instance_market ( instance ) if not instance_market . az : logger . warning ( f"Instance {instance['InstanceId']} missing AZ info, likely already terminated so skipping" , ) instance_ids . remove ( instance [ "InstanceId" ] ) continue instance_weights [ instance [ "InstanceId" ] ] = self . market_weight ( get_instance_market ( instance ) ) # AWS API recommends not terminating more than 1000 instances at a time, and to # terminate larger numbers in batches terminated_instance_ids = [ ] for batch in range ( 0 , len ( instance_ids ) , batch_size ) : response = ec2 . terminate_instances ( InstanceIds = instance_ids [ batch : batch + batch_size ] ) terminated_instance_ids . extend ( [ instance [ "InstanceId" ] for instance in response [ "TerminatingInstances" ] ] ) # It's possible that not every instance is terminated.  The most likely cause for this # is that AWS terminated the instance in between getting its status and the terminate_instances # request.  This is probably fine but let's log a warning just in case. missing_instances = set ( instance_ids ) - set ( terminated_instance_ids ) if missing_instances : logger . warning ( "Some instances could not be terminated; they were probably killed previously" ) logger . warning ( f"Missing instances: {list(missing_instances)}" ) terminated_capacity = sum ( instance_weights [ i ] for i in instance_ids ) logger . info ( f"{self.id} terminated weight: {terminated_capacity}; instances: {terminated_instance_ids}" ) return terminated_instance_ids