1

I am writing a program using AWS Java SDK to create EC2 instances and do some processing once they are launched.

I have written the following code but I know there could be a better way to do this:

public static void main(String[] args) {

   // Some code initialization here
   Instance ec2instance; 

   do {    
        try {
              Thread.sleep(sleep_cyle);
            } catch (InterruptedException ex) {
                System.out.println(ex.getMessage());
            }

       } while(ec2instance.getState().getCode() != 16);

       //Proceed with processing after instance is running
}

Thank you.

AngryPanda
  • 1,261
  • 2
  • 19
  • 42

1 Answers1

0

Since there is nothing reporting back to your application related to status changes, the only way to identify changes is to poll every 15-30 seconds.

There are rare cases where an instance may simply fail to launch. Your code should expect the possibility of going from pending to terminated.

datasage
  • 19,153
  • 2
  • 48
  • 54