I have the following code that I'd like to understand:
DescribeInstanceStatusRequest instanceRequest = new DescribeInstanceStatusRequest().withInstanceIds([String of our instanceId]);
AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
ec2.startInstances([instanceID string]);
ec2.waiters().instanceStatusOK().run(new WaiterParameters<DescribeInstanceStatusRequest>().withRequest(instanceRequest));
I was assured that this will start my ec2 instance and check that it it's running. I also understand that documentation states that instanceStatusOk()
will poll until my desired state is achieved. How does the 4th line know what my desired state is?
CodePudding user response:
Instance status can be one of:
ok | impaired | initializing | insufficient-data | not-applicable
The instanceStatusOK waiter method is a helper that creates a pre-configured waiter which can then be run to poll until the waiter determines whether or not the EC2 instance has the desired status (ok
) or not.
It knows your desired status (of ok
) because it's pre-configured with that status. You can create waiters for other status values but they don't have equivalent pre-configured helpers afaik (presumably because they're not as useful, in general).