public void terminateInstancesInASGroup(List<String> instanceIds, boolean decrementDesiredCapacity) { logger.info("terminate instances in auto scaling group, instanceIds={}, decrementDesiredCapacity={}", instanceIds, decrementDesiredCapacity); for (String instanceId : instanceIds) { try { autoScaling.terminateInstanceInAutoScalingGroup(new TerminateInstanceInAutoScalingGroupRequest() .withInstanceId(instanceId) .withShouldDecrementDesiredCapacity(decrementDesiredCapacity)); } catch (AmazonClientException e) { logger.warn("failed to terminate instance in auto scaling group, it could be already terminated by auto scaling group, instanceId={}", instanceId, e); } } }
@Override public Void call() { TerminateInstanceInAutoScalingGroupRequest request = new TerminateInstanceInAutoScalingGroupRequest() .withInstanceId(this.instanceId).withShouldDecrementDesiredCapacity(true); getClient().getApi().terminateInstanceInAutoScalingGroup(request); awaitTermination(this.instanceId); return null; }