Module: Bootstrap

Defined in:
lib/aws_lambda_ric/bootstrap.rb

Overview

Bootstrap runtime

Class Method Summary collapse

Class Method Details

.bootstrap_handlerObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/aws_lambda_ric/bootstrap.rb', line 26

def self.bootstrap_handler
  if ARGV.empty?
    puts 'No handler specified, exiting Runtime Interface Client.'
    exit
  end
  app_root = Dir.pwd
  handler = ARGV[0]
  lambda_runner = AwsLambdaRuntimeInterfaceClient::LambdaRunner.new(fetch_runtime_server, get_user_agent)
  puts "Executing '#{handler}' in function directory '#{app_root}'"
  lambda_runner.run(app_root, handler)
end

.bootstrap_telemetry_log_sink(path_to_fd = '/proc/self/fd/') ⇒ Object



18
19
20
21
22
23
24
# File 'lib/aws_lambda_ric/bootstrap.rb', line 18

def self.bootstrap_telemetry_log_sink(path_to_fd='/proc/self/fd/')
  fd = ENV.fetch(AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper::ENV_VAR_TELEMETRY_LOG_FD)
  ENV.delete(AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper::ENV_VAR_TELEMETRY_LOG_FD)
  AwsLambdaRuntimeInterfaceClient::TelemetryLoggingHelper.new(fd, path_to_fd)
rescue KeyError
  puts 'Skipped bootstraping TelemetryLog'
end

.fetch_runtime_serverObject



11
12
13
14
15
16
# File 'lib/aws_lambda_ric/bootstrap.rb', line 11

def self.fetch_runtime_server
  ENV.fetch(AwsLambdaRuntimeInterfaceClient::LambdaRunner::ENV_VAR_RUNTIME_API)
rescue KeyError
  puts 'Failed to get runtime server address from AWS_LAMBDA_RUNTIME_API env variable'
  exit(-2)
end

.get_user_agentObject



38
39
40
41
42
43
# File 'lib/aws_lambda_ric/bootstrap.rb', line 38

def self.get_user_agent
  ruby_version = RUBY_VERSION.to_s
  version = AwsLambdaRuntimeInterfaceClient::VERSION
 
  "aws-lambda-ruby/#{ruby_version}-#{version}"
end

.startObject



6
7
8
9
# File 'lib/aws_lambda_ric/bootstrap.rb', line 6

def self.start
  bootstrap_telemetry_log_sink
  bootstrap_handler
end