Class: Fluent::LambdaOutput

Inherits:
BufferedOutput
  • Object
show all
Includes:
SetTagKeyMixin, SetTimeKeyMixin
Defined in:
lib/fluent/plugin/out_lambda.rb

Instance Method Summary collapse

Constructor Details

#initializeLambdaOutput

Returns a new instance of LambdaOutput.



22
23
24
25
26
# File 'lib/fluent/plugin/out_lambda.rb', line 22

def initialize
  super
  require 'aws-sdk-core'
  require 'json'
end

Instance Method Details

#configure(conf) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fluent/plugin/out_lambda.rb', line 28

def configure(conf)
  super

  aws_opts = {}

  if @profile
    credentials_opts = {:profile_name => @profile}
    credentials_opts[:path] = @credentials_path if @credentials_path
    credentials = Aws::SharedCredentials.new(credentials_opts)
    aws_opts[:credentials] = credentials
  end

  aws_opts[:access_key_id] = @aws_key_id if @aws_key_id
  aws_opts[:secret_access_key] = @aws_sec_key if @aws_sec_key
  aws_opts[:region] = @region if @region
  aws_opts[:endpoint] = @endpoint if @endpoint

  configure_aws(aws_opts)
end

#format(tag, time, record) ⇒ Object



54
55
56
# File 'lib/fluent/plugin/out_lambda.rb', line 54

def format(tag, time, record)
  [tag, time, record].to_msgpack
end

#startObject



48
49
50
51
52
# File 'lib/fluent/plugin/out_lambda.rb', line 48

def start
  super

  @client = create_client
end

#write(chunk) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fluent/plugin/out_lambda.rb', line 58

def write(chunk)
  chunk = chunk.to_enum(:msgpack_each)

  chunk.select {|tag, time, record|
    if @function_name or record['function_name']
      true
    else
      log.warn("`function_name` key does not exist: #{[tag, time, record].inspect}")
      false
    end
  }.each {|tag, time, record|
    func_name = @function_name || record['function_name']

    @client.invoke_async(
      :function_name => func_name,
      :invoke_args => JSON.dump(record),
    )
  }
end