Method: Jets::CLI::Call#invoke

Defined in:
lib/jets/cli/call.rb

#invokeObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jets/cli/call.rb', line 24

def invoke
  params = {
    function_name: function_name,
    invocation_type: invocation_type, # Event or RequestResponse
    log_type: @log_type, # pretty sweet
    payload: payload # json string
    # qualifier: @qualifier # "1", version or alias published version. not used yet
  }

  resp = nil
  begin
    resp = lambda_client.invoke(params)
    # Capture @log_last_4kb for log_last_4kb method
    # log_last_4kb is an interface method used by Exec::Command
    @log_last_4kb = resp.log_result
  rescue Aws::Lambda::Errors::ResourceNotFoundException
    warn "ERROR: function #{function_name} not found".color(:red)
    warn "Maybe check the spelling or the AWS_PROFILE?"
    return resp
  end

  if !/^2/.match?(resp[:status_code].to_s)
    warn "ERROR: Lambda function #{function_name} returned status code: #{resp[:status_code]}".color(:red)
    warn resp
  end

  if verbose? && invocation_type != "Event"
    log_last_4kb
  end

  if invocation_type == "Event"
    resp
  else
    text = resp.payload.read # already been normalized/JSON.dump by AWS
    data = JSON.parse(text)
    ActiveSupport::HashWithIndifferentAccess.new(data)
  end
end