When starting an instance on Amazon EC2, how would I detect a failure, for instance, if there’s no machine available to fulfill my request? I’m using one of the less-common machine types and am concerned it won’t start up, but am having trouble finding out what message to look for to detect this.
I’m using the EC2 commandline tools to do this. I know I can look for ‘running’ when I do ec2-describe-instance to see if the machine is up, but don’t know what to look for to see if the startup failed.
Thanks!
The output from
ec2-start-instancesonly returns youstopped pending, and as you say you need to useec2-describe-instancesto retrieve the state.For that, you have a couple of choices; you can either use a loop to check for
instance-state-name, looking for a result ofrunningorstopped; alternatively you could look at either thereasonorstate-reason-codefields; unfortunately you’ll need to trigger the failure you’re worried about, to obtain the values that indicate failure.The batch file I use to wait for a successful startup (fill in the underscores):