Make the ec2 wait code a little smarter

The code to determine the number of running instances could blow up
if the response from AWS did not actually contain any data. This code
makes it a bit smarter in handling, so that it will wait for a valid
response regardless of the wait condition.

Fixes #3980