April 2018
Intermediate to advanced
280 pages
8h 37m
English
After you launch an EC2 instance, it might be necessary to check the state of the instance to determine whether the instance is ready for use. The state of the instance can be easily determined by checking the State property of the Instance class object.
You can simply use the RunInstancesResponse object that you created for invoking the RunInstances() function, and get a list of instances by using the Reservation.Instances property. The list can then be iterated and checked for the State property to determine the state of the instance.
The following code snippet shows how this is done. You add this code in the preceding program inside the try block:
var instances = response.Reservation.Instances;