Module: WolfCore::LambdaFunctionOperations

Included in:
ApplicationService, Barton::Routing
Defined in:
lib/wolf_core/infrastructure/lambda_function_operations.rb

Instance Method Summary collapse

Instance Method Details

#deep_parse_json(input) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wolf_core/infrastructure/lambda_function_operations.rb', line 15

def deep_parse_json(input)
  while input.is_a?(String)
    begin
      input = JSON.parse(input)
    rescue JSON::ParserError
      break
    end
  end

  input&.with_indifferent_access || {}
end

#get_event_params(event) ⇒ Object



9
10
11
12
13
# File 'lib/wolf_core/infrastructure/lambda_function_operations.rb', line 9

def get_event_params(event)
  event_body = event['body']
  return deep_parse_json(event_body) if event_body.present?
  event.with_indifferent_access
end

#invoke_lambda(function_name:, payload:, invocation_type: nil) ⇒ Object



3
4
5
6
7
# File 'lib/wolf_core/infrastructure/lambda_function_operations.rb', line 3

def invoke_lambda(function_name:, payload:, invocation_type: nil)
  WolfCore::LambdaFunctionDataSource.invoke(
    function_name: function_name, payload: payload, invocation_type: invocation_type
  )
end

#result_to_response(result) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/wolf_core/infrastructure/lambda_function_operations.rb', line 27

def result_to_response(result)
  if result.success?
    { statusCode: 200, body: result.data.to_h.to_json }
  else
    { statusCode: result.error.status || 422, body: result.error.to_h.to_json }
  end
end