# File lib/fog/aws/requests/lambda/create_function.rb, line 66
        def create_function(params={})
          response = Excon::Response.new

          runtime = params.delete('Runtime') || 'nodejs'
          if !%w(nodejs java8).include?(runtime)
            message = 'ValidationException: Runtime must be nodejs or java8.'
            raise Fog::AWS::Lambda::Error, message
          end

          unless code = params.delete('Code')
            message = 'ValidationException: Code cannot be blank.'
            raise Fog::AWS::Lambda::Error, message
          end

          unless function_name = params.delete('FunctionName')
            message = 'ValidationException: Function name cannot be blank.'
            raise Fog::AWS::Lambda::Error, message
          end

          unless handler = params.delete('Handler')
            message = 'ValidationException: Handler cannot be blank.'
            raise Fog::AWS::Lambda::Error, message
          end

          unless role = params.delete('Role')
            message = 'ValidationException: Role cannot be blank.'
            raise Fog::AWS::Lambda::Error, message
          end

          code_size = if code.has_key?('ZipFile')
            Base64.decode64(code['ZipFile']).length
          else
            Fog::Mock.random_numbers(5).to_i
          end

          description = params.delete('Description')

          function = {}
          begin
            opts     = { 'FunctionName' => function_name }
            function = self.get_function_configuration(opts).body
          rescue Fog::AWS::Lambda::Error => e
            # ignore: if the function doesn't exist we are OK.
          end

          if !function.empty?
            message  = "ResourceConflictException => "
            message << "Function already exist: #{function_name}"
            raise Fog::AWS::Lambda::Error, message
          end

          function_path = "function:#{function_name}"
          function_arn = Fog::AWS::Mock.arn(
            'lambda',
            self.account_id,
            function_path,
            self.region
          )

          function = {
            'CodeSize'     => code_size,
            'FunctionArn'  => function_arn,
            'FunctionName' => function_name,
            'Handler'      => handler,
            'LastModified' => Time.now.utc,
            'MemorySize'   => params.delete('MemorySize') || 128,
            'Timeout'      => params.delete('Timeout')    || 3,
            'Role'         => role,
            'Runtime'      => runtime
          }
          function['Description'] = description if description

          self.data[:functions][function_arn] = function
          response.body   = function
          response.status = 200
          response
        end