-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathlambda.rb
More file actions
executable file
·52 lines (44 loc) · 936 Bytes
/
lambda.rb
File metadata and controls
executable file
·52 lines (44 loc) · 936 Bytes
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
46
47
48
49
50
51
52
#!/usr/bin/env ruby
# frozen_string_literal: true
BUNDLE_SETUP = 'vendor/bundle/bundler/setup'
dir = File.dirname(__FILE__)
if File.exist?("#{dir}/#{BUNDLE_SETUP}.rb")
require_relative 'vendor/bundle/bundler/setup'
end
require 'oj'
require 'colored2'
def handler(event:, context:)
Oj.dump(
statusCode: context[:status],
contentType: context[:content_type],
body: handler_body(event)
)
end
private
def handler_body(event)
<<~BODY.gsub(/^\s+/, '')
<html>
<head>
<title>#{event[:title]}</title>
</head>
<body>
<h1>#{event[:header]}</h1>
<blockquote>#{event[:body]}</blockquote>
</body>
</html>
BODY
end
public
if $PROGRAM_NAME == __FILE__
puts handler(
event: {
header: 'Welcome to Lambda!',
title: 'Lambda Demo',
body: 'Lambdas are cool. And so are you!'
},
context: {
status: 200,
content_type: 'text/html'
}
)
end