Module: WolfCore::LambdaFunctionDataSource

Defined in:
lib/wolf_core/infrastructure/lambda_function_data_source.rb

Class Method Summary collapse

Class Method Details

.clientObject



22
23
24
# File 'lib/wolf_core/infrastructure/lambda_function_data_source.rb', line 22

def client
  @@client
end

.initObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/wolf_core/infrastructure/lambda_function_data_source.rb', line 5

def init
  timeout = ENV.fetch('AWS_LAMBDA_CLIENT_TIMEOUT', 900)
  client_config = {
    access_key_id: ENV.fetch('AWS_KEY_ID', nil),
    secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY', nil),
    region: ENV.fetch('AWS_REGION', nil),
    endpoint: ENV.fetch('AWS_LAMBDA_FUNCTION_ENDPOINT', nil),
    http_open_timeout: timeout,
    http_read_timeout: timeout,
  }

  client_config = client_config.compact
  return if client_config.empty?

  @@client = Aws::Lambda::Client.new(client_config)
end

.invoke(function_name:, payload:, invocation_type: nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/wolf_core/infrastructure/lambda_function_data_source.rb', line 26

def invoke(function_name:, payload:, invocation_type: nil)
  parsed_payload = JSON.generate(payload)
  invocation_type ||= 'Event'
  # use invocation_type = 'Event' to make an asynchronous call
  # use invocation_type = 'RequestResponse' to make a synchronous call
  response = @@client.invoke({
    function_name: function_name,
    invocation_type: invocation_type,
    log_type: 'Tail',
    payload: parsed_payload
  })
  return if invocation_type == 'Event'
  JSON.parse(response.payload.string)
end