I am trying to automate some stuff on AWS and I am using Java API to do this. I am able to launch number of instances I want, but I am unable to find the right class or method that can fetch me the current state of the instance (like running, stopped etc).
I tried this
DescribeInstanceStatusRequest describeInstance = new DescribeInstanceStatusRequest().withInstanceIds(instances.get(i).getInstanceId());
DescribeInstanceStatusResult attr = ec2.describeInstanceStatus(describeInstance);
List<InstanceStatus> state = attr.getInstanceStatuses();
not sure why the instance status is a list
Can someone please point me to right API call.
Thanks in advance
I figured the issue. working code
DescribeInstanceStatusRequest describeInstanceRequest = new DescribeInstanceStatusRequest().withInstanceIds(i-xxxxxxxx);
DescribeInstanceStatusResult describeInstanceResult = ec2.describeInstanceStatus(describeInstanceRequest);
List<InstanceStatus> state = describeInstanceResult.getInstanceStatuses();
while (state.size() < 1) {
// Do nothing, just wait, have thread sleep if needed
describeInstanceResult = ec2.describeInstanceStatus(describeInstanceRequest);
state = describeInstanceResult.getInstanceStatuses();
}
String status = state.get(0).getInstanceState().getName();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With