Source:
private void waitForGroup(AmazonEC2Client amClient, AmazonAutoScalingClient asClient, AmazonAutoScalingRetryClient asRetryClient, String autoScalingGroupName, Integer requiredInstanceCount, Long stackId) throws AmazonAutoscalingFailed { Waiter<DescribeAutoScalingGroupsRequest> groupInServiceWaiter = asClient.waiters().groupInService(); PollingStrategy backoff = getBackoffCancellablePollingStrategy(new StackCancellationCheck(stackId)); PollingStrategy slowStart = SlowStartCancellablePollingStrategy.getExpectedRuntimeCancellablePollingStrategy( new StackCancellationCheck(stackId), EXPECTED_SCALEUP_TIME_SECONDS); try { groupInServiceWaiter.run(new WaiterParameters<>(new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(autoScalingGroupName)) .withPollingStrategy(backoff)); } catch (Exception e) { throw new AmazonAutoscalingFailed(e.getMessage(), e); } long startTime = System.currentTimeMillis(); Waiter<DescribeAutoScalingGroupsRequest> instancesInServiceWaiter = customAmazonWaiterProvider .getAutoscalingInstancesInServiceWaiter(asClient, requiredInstanceCount); try { instancesInServiceWaiter.run(new WaiterParameters<>(new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(autoScalingGroupName)) .withPollingStrategy(slowStart)); } catch (Exception e) { throw new AmazonAutoscalingFailed(e.getMessage(), e); } LOGGER.info("Done with instancesInServiceWaiter. Duration={}", System.currentTimeMillis() - startTime); List<String> instanceIds = cloudFormationStackUtil.getInstanceIds(asRetryClient, autoScalingGroupName); if (requiredInstanceCount != 0) { List<List<String>> partitionedInstanceIdsList = Lists.partition(instanceIds, MAX_INSTANCE_ID_SIZE); Waiter<DescribeInstancesRequest> instanceRunningStateWaiter = amClient.waiters().instanceRunning(); for (List<String> partitionedInstanceIds : partitionedInstanceIdsList) { startTime = System.currentTimeMillis(); try { instanceRunningStateWaiter.run(new WaiterParameters<>(new DescribeInstancesRequest().withInstanceIds(partitionedInstanceIds)) .withPollingStrategy(backoff)); } catch (Exception e) { throw new AmazonAutoscalingFailed(e.getMessage(), e); } } } }

Target:
private void waitForGroup(AmazonEC2Client amClient, AmazonAutoScalingClient asClient, AmazonAutoScalingRetryClient asRetryClient, String autoScalingGroupName, Integer requiredInstanceCount, Long stackId) throws AmazonAutoscalingFailed { Waiter<DescribeAutoScalingGroupsRequest> groupInServiceWaiter = asClient.waiters().groupInService(); PollingStrategy backoff = getBackoffCancellablePollingStrategy(new StackCancellationCheck(stackId)); PollingStrategy slowStart = SlowStartCancellablePollingStrategy.getExpectedRuntimeCancellablePollingStrategy( new StackCancellationCheck(stackId), EXPECTED_SCALEUP_TIME_SECONDS); try { groupInServiceWaiter.run(new WaiterParameters<>(new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(autoScalingGroupName)) .withPollingStrategy(backoff)); } catch (Exception e) { throw new AmazonAutoscalingFailed(e.getMessage(), e); } long startTime = System.currentTimeMillis(); Waiter<DescribeAutoScalingGroupsRequest> instancesInServiceWaiter = customAmazonWaiterProvider .getAutoscalingInstancesInServiceWaiter(asClient, requiredInstanceCount); try { instancesInServiceWaiter.run(new WaiterParameters<>(new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(autoScalingGroupName)) .withPollingStrategy(slowStart)); } catch (Exception e) { throw new AmazonAutoscalingFailed(e.getMessage(), e); } LOGGER.info("Done with instancesInServiceWaiter. Duration={}", System.currentTimeMillis() - startTime); List<String> instanceIds = cloudFormationStackUtil.getInstanceIds(asRetryClient, autoScalingGroupName); if (requiredInstanceCount != 0) { List<List<String>> partitionedInstanceIdsList = Lists.partition(instanceIds, MAX_INSTANCE_ID_SIZE); Waiter<DescribeInstancesRequest> instanceRunningStateWaiter = amClient.waiters().instanceRunning(); for (List<String> partitionedInstanceIds : partitionedInstanceIdsList) { try { instanceRunningStateWaiter.run(new WaiterParameters<>(new DescribeInstancesRequest().withInstanceIds(partitionedInstanceIds)) .withPollingStrategy(backoff)); } catch (Exception e) { throw new AmazonAutoscalingFailed(e.getMessage(), e); } } } }