Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit a70b88e

Browse files
authored
Merge pull request #63 from triggermesh/ruby-ce-ctx
CE context headers in Ruby 25 runtime
2 parents 83d939e + 40d2e94 commit a70b88e

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

ruby25/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ENV LAMBDA_TASK_ROOT "/opt"
1515

1616
COPY --from=downloader /opt/aws-custom-runtime /opt/
1717
COPY --from=lambda /var/runtime/lib /opt
18+
COPY lambda_context.rb /opt/
1819

1920
RUN mv /opt/runtime.rb /opt/bootstrap
2021
RUN sed -i /opt/lambda_server.rb -e 's|http://127.0.0.1:9001/2018-06-01|http://127.0.0.1/2018-06-01|'

ruby25/lambda_context.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
3+
class LambdaContext
4+
attr_reader :aws_request_id, :invoked_function_arn, :log_group_name,
5+
:log_stream_name, :function_name, :memory_limit_in_mb, :function_version,
6+
:identity, :client_context, :ce, :deadline_ms
7+
8+
def initialize(request)
9+
@clock_diff = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond) - Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
10+
@deadline_ms = request['Lambda-Runtime-Deadline-Ms'].to_i
11+
@aws_request_id = request['Lambda-Runtime-Aws-Request-Id']
12+
@invoked_function_arn = request['Lambda-Runtime-Invoked-Function-Arn']
13+
@log_group_name = ENV['AWS_LAMBDA_LOG_GROUP_NAME']
14+
@log_stream_name = ENV['AWS_LAMBDA_LOG_STREAM_NAME']
15+
@function_name = ENV["AWS_LAMBDA_FUNCTION_NAME"]
16+
@memory_limit_in_mb = ENV['AWS_LAMBDA_FUNCTION_MEMORY_SIZE']
17+
@function_version = ENV['AWS_LAMBDA_FUNCTION_VERSION']
18+
if request['Lambda-Runtime-Cognito-Identity']
19+
@identity = JSON.parse(request['Lambda-Runtime-Cognito-Identity'])
20+
end
21+
if request['Lambda-Runtime-Client-Context']
22+
@client_context = JSON.parse(request['Lambda-Runtime-Client-Context'])
23+
end
24+
if request['Lambda-Runtime-Cloudevents-Context']
25+
@ce = JSON.parse(request['Lambda-Runtime-Cloudevents-Context'])
26+
end
27+
end
28+
29+
def get_remaining_time_in_millis
30+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) + @clock_diff
31+
remaining = @deadline_ms - now
32+
remaining > 0 ? remaining : 0
33+
end
34+
end

0 commit comments

Comments
 (0)