There is no event model or other signal raised by the SDK to tell you when an EC2 object changes state - the only way to find out is to issue a DescribeXXXXXXXX call to the object on a repeated basis, say, once every 30 seconds, until the status field changes.
It takes a minimum amount of time to make a call and answer, so you need to find an interval that does not start requests before the previous one is completed. Or just wait for an answer, and then wait a few more seconds before resending the call. You also don't want to spam AWS APIs with fast requests, even if they are synchronized between responses. In my controller application, I set the interval after 30 seconds, issued a request, waited for a response, and then subtracted the elapsed time from the interval and continued to sleep. In a multi-threaded model, I can thus monitor state changes on many objects at the same time, without overloading either my local processor or the API.
After a state change has been detected (and if you expect a new state to be waiting for you - be sure to handle the failure modes), you can get a wide range of descriptive information, including a public DNS address (in the case of instance objects) from the structure returned in the API response object.
Eight-bit guru
source share