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.



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

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

Instance Method Details

#configure(conf) ⇒ Object



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

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



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

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

#startObject



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

def start
  super

  @client = create_client
end

#write(chunk) ⇒ Object



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

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']

    payload = {
      :function_name => func_name,
      :payload => JSON.dump(record),
      :invocation_type => 'Event',
    }
    payload[:qualifier] = @qualifier unless @qualifier.nil?

    @client.invoke(payload)
  }
end