code: def create_ondemand_instances(ec2, image_id, spec, num_instances=1):
      
      instance_type = spec['instance_type']
      log.info('Creating %s instance(s) ... ', instance_type)
      for attempt in retry_ec2(retry_for=a_long_time,
                               retry_while=inconsistencies_detected):
          with attempt:
              return ec2.run_instances(image_id,
                                       min_count=num_instances,
                                       max_count=num_instances,
                                       **spec).instances
docs: Requests the RunInstances EC2 API call but accounts for the race between recently created
      instance profiles, IAM roles and an instance creation that refers to them.
  
      :rtype: list[Instance]