title: How to get current EC2 instance state in Java
body: <p>I'm looking for some code that will return the current instance state regardless of whether the instance is currently running or not.  I found some code that will return the desired result on a running instance, but when trying to find one that will work on stopped instances, I was overwhelmed by a number of similar looking classes that appeared to perform a similar operation, but in the end, did not work or were poorly documented.</p>
  
  <p>Anyway, the running instance version of the code is below:</p>
  
  <pre><code>public Integer getInstanceStatus(String instanceId) {
      DescribeInstanceStatusRequest describeInstanceRequest = new DescribeInstanceStatusRequest().withInstanceIds(instanceId);
      DescribeInstanceStatusResult describeInstanceResult = ec2.describeInstanceStatus(describeInstanceRequest);
      List&lt;InstanceStatus&gt; state = describeInstanceResult.getInstanceStatuses();
      return state.get(0).getInstanceState().getCode();
  }
  </code></pre>
  
  <p>So I'm basically looking for the equivalent that does not have the <code>DescribeInstanceStatus</code>'s restriction that requires the instance to be running.  I'd assume this is possible since the <code>getCode()</code> documentation shows it as being able to return the value 80 which denotes a <strong>stopped</strong> instance.</p>