In checking unutilized reserved instances, I retrieve those using python script from Github called ec2-check-reserved-instances. It contains:
running_instances = {}
for reservation in reservations:
for instance in reservation.instances:
if instance.state != "running":
sys.stderr.write("Disqualifying instance %s: not running\n" % ( instance.id ) )
elif instance.spot_instance_request_id:
sys.stderr.write("Disqualifying instance %s: spot\n" % ( instance.id ) )
else:
**if instance.vpc_id:**
print "Does not support vpc yet, please be careful when trusting these results"
else:
az = instance.placement
instance_type = instance.instance_type
running_instances[ (instance_type, az ) ] = running_instances.get( (instance_type, az ) , 0 ) + 1
# pprint( running_instances )
It gives me running instances as empty and not reserved instance also empty, but printing unused reserved instances.
When I use the same code without checking if instance.vpc_id
, like this:
running_instances = {}
for reservation in reservations:
for instance in reservation.instances:
if instance.state != "running":
sys.stderr.write("Disqualifying instance %s: not running\n" % ( instance.id ) )
elif instance.spot_instance_request_id:
sys.stderr.write("Disqualifying instance %s: spot\n" % ( instance.id ) )
else:
az = instance.placement
instance_type = instance.instance_type
running_instances[ (instance_type, az ) ] = running_instances.get( (instance_type, az ) , 0 ) + 1
# pprint( running_instances )
It gives me a Running instances list and not created instances. But it does not shows unused reserved instances. Just displays "you have no unused reserved instances".
Why am I getting a different result when I am checking with and without instance.vpc_id
? Which one is right?
Actually it is checking out unutilized instances by comparing running and reserved instances part.
Also what is meant by spot instances, why we have to ignore spot instances too?