# File lib/fog/aws/requests/compute/request_spot_instances.rb, line 96
        def request_spot_instances(image_id, instance_type, spot_price, options = {})
          response = Excon::Response.new
          id       = Fog::AWS::Mock.spot_instance_request_id

          if (image_id && instance_type && spot_price)
            response.status = 200

            all_instance_types = flavors.map { |f| f.id }
            if !all_instance_types.include?(instance_type)
              message = "InvalidParameterValue => Invalid value '#{instance_type}' for InstanceType."
              raise Fog::Compute::AWS::Error.new(message)
            end

            spot_price = spot_price.to_f
            if !(spot_price > 0)
              message = "InvalidParameterValue => Value (#{spot_price}) for parameter price is invalid."
              message << " \"#{spot_price}\" is an invalid spot instance price"
              raise Fog::Compute::AWS::Error.new(message)
            end

            if !image_id.match(/^ami-[a-f0-9]{8}$/)
              message = "The image id '[#{image_id}]' does not exist"
              raise Fog::Compute::AWS::NotFound.new(message)
            end

          else
            message = 'MissingParameter => '
            message << 'The request must contain the parameter '
            if !image_id
              message << 'image_id'
            elsif !instance_type
              message << 'instance_type'
            else
              message << 'spot_price'
            end
            raise Fog::Compute::AWS::Error.new(message)
          end

          for key in %w(AvailabilityZoneGroup LaunchGroup)
            if options.is_a?(Hash) && options.key?(key)
              Fog::Logger.warning("#{key} filters are not yet mocked [light_black](#{caller.first})[/]")
              Fog::Mock.not_implemented
            end
          end

          launch_spec = {
            'iamInstanceProfile' => {},
            'blockDeviceMapping' => options['LaunchSpecification.BlockDeviceMapping'] || [],
            'groupSet'           => options['LaunchSpecification.SecurityGroupId']    || ['default'],
            'imageId'            => image_id,
            'instanceType'       => instance_type,
            'monitoring'         => options['LaunchSpecification.Monitoring.Enabled'] || false,
            'subnetId'           => options['LaunchSpecification.SubnetId']           || nil,
            'ebsOptimized'       => options['LaunchSpecification.EbsOptimized']       || false,
            'keyName'            => options['LaunchSpecification.KeyName']            || nil
          }

          if iam_arn = options['LaunchSpecification.IamInstanceProfile.Arn']
            launch_spec['iamInstanceProfile'].merge!('Arn' => iam_arn)
          end

          if iam_name = options['LaunchSpecification.IamInstanceProfile.Name']
            launch_spec['iamInstanceProfile'].merge!('Name' => iam_name)
          end

          spot_request = {
            'launchSpecification'   => launch_spec,
            'spotInstanceRequestId' => id,
            'spotPrice'             => spot_price,
            'type'                  => options['Type'] || 'one-time',
            'state'                 => 'open',
            'fault'                 => {
              'code'    => 'pending-evaluation',
              'message' => 'Your Spot request has been submitted for review, and is pending evaluation.'
            },
            'createTime'         => Time.now,
            'productDescription' => 'Linux/UNIX'
          }

          self.data[:spot_requests][id] = spot_request

          response.body = {
            'spotInstanceRequestSet' => [spot_request],
            'requestId' => Fog::AWS::Mock.request_id
          }

          response
        end