Created
August 18, 2015 06:37
-
-
Save anonymous/919c6345afb5c589d398 to your computer and use it in GitHub Desktop.
AWS instance creating helper method that sleeps on a timely manner until instances are ready
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void sleepUntilInstancesIsRunning(AmazonEC2 ec2, Set<String> instanceIdList) throws InterruptedException { | |
while(true) { | |
DescribeInstancesResult instanceStatusResult = ec2.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceIdList)); | |
if(Iterables.all(instanceStatusResult.getReservations(), new Predicate<Reservation>() { | |
@Override | |
public boolean apply(Reservation input) { | |
return Iterables.all(input.getInstances(), new Predicate<Instance>() { | |
@Override | |
public boolean apply(Instance input) { | |
return input.getState().getName().equalsIgnoreCase(InstanceStateName.Running.toString()); | |
} | |
}); | |
} | |
})){ | |
break; | |
} else { | |
System.out.println("waiting..."); | |
Thread.sleep(1000); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment