1

I am calculating my total number of reserved instance on the basis of instance_type and I'm storing this in a dictionary by instance_type as a key.

Firstly, I'm finding my all reserved instances by get_all_reserved_instances(), then for each instance returned by this, I do this:

if each.state != 'retired':
 key = str(each.instance_type)
 res_count[key]+=each.instance_count

I'm also calculating total number of instances on the basis of instance_type. Firstly, I'm finding my all instances by get_all_instances() and then for each instance_type I do this:

if each.state == 'running':
 key = str(each.instance_type)
 all_count[key]+=1

Now for one instance type it returns:

all_count = 17

res_count = 19

How's it possible that res_count is greater than all_count? res_count can be equal to all_count, if there is no ondemand instance, but why this is greater than all_count? can a non-retired instance also be not running ? if it is,then i think this is case for this difference.

Is there any fault of using state or is there another reason?

Vikas Saini
  • 163
  • 3
  • 1
    Log into the console, click on Reserved Instances, and see how many you've actually reserved. You can absolutely have more reserved instances than "all instances"--just because you reserved an instance doesn't mean that you're actually making use of the reservation. – Will Jan 02 '16 at 19:05
  • 1
    it means we reserved instances, but we are not using them. that's why it is showing reserved instances more than total instances. – Vikas Saini Jan 04 '16 at 05:41

1 Answers1

0

can a non-retired instance also be not running?

  • Yes, an AWS EC2 instance can be in multiple states in addition to running. Per the latest official documentation in this link Instance Life cycle, there is no retired state but the line each.state != 'retired' in your code will pull all the reserved instances nevertheless.

How's it possible that res_count is greater than all_count?

  • You have instances in a state other than running.
Daniel t.
  • 9,061
  • 1
  • 32
  • 36