-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathbootstrap.rb
45 lines (37 loc) · 1.37 KB
/
bootstrap.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require_relative '../aws_lambda_ric'
# Bootstrap runtime
module Bootstrap
def self.start
bootstrap_telemetry_log_sink
bootstrap_handler
end
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
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
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
def self.get_user_agent
ruby_version = RUBY_VERSION.to_s
version = AwsLambdaRuntimeInterfaceClient::VERSION
"aws-lambda-ruby/#{ruby_version}-#{version}"
end
end