lamby_updated 5.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.devcontainer/Dockerfile +1 -0
- data/.devcontainer/devcontainer.json +20 -0
- data/.github/workflows/test.yml +35 -0
- data/.gitignore +15 -0
- data/CHANGELOG.md +364 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +204 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +27 -0
- data/bin/bootstrap +2 -0
- data/bin/console +14 -0
- data/bin/setup +6 -0
- data/bin/test +8 -0
- data/bin/update +5 -0
- data/images/social.png +0 -0
- data/images/social2.png +0 -0
- data/lamby.gemspec +32 -0
- data/lib/lamby/cold_start_metrics.rb +83 -0
- data/lib/lamby/config.rb +86 -0
- data/lib/lamby/debug.rb +47 -0
- data/lib/lamby/handler.rb +137 -0
- data/lib/lamby/logger.rb +18 -0
- data/lib/lamby/proxy_context.rb +25 -0
- data/lib/lamby/proxy_server.rb +36 -0
- data/lib/lamby/rack.rb +115 -0
- data/lib/lamby/rack_alb.rb +82 -0
- data/lib/lamby/rack_http.rb +107 -0
- data/lib/lamby/rack_rest.rb +53 -0
- data/lib/lamby/railtie.rb +9 -0
- data/lib/lamby/ssm_parameter_store.rb +155 -0
- data/lib/lamby/tasks.rake +19 -0
- data/lib/lamby/version.rb +3 -0
- data/lib/lamby.rb +53 -0
- data/vendor/.keep +0 -0
- metadata +233 -0
data/Gemfile.lock
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
lamby_updated (5.2.1)
|
5
|
+
lambda-console-ruby
|
6
|
+
rack
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actioncable (7.0.4.3)
|
12
|
+
actionpack (= 7.0.4.3)
|
13
|
+
activesupport (= 7.0.4.3)
|
14
|
+
nio4r (~> 2.0)
|
15
|
+
websocket-driver (>= 0.6.1)
|
16
|
+
actionmailbox (7.0.4.3)
|
17
|
+
actionpack (= 7.0.4.3)
|
18
|
+
activejob (= 7.0.4.3)
|
19
|
+
activerecord (= 7.0.4.3)
|
20
|
+
activestorage (= 7.0.4.3)
|
21
|
+
activesupport (= 7.0.4.3)
|
22
|
+
mail (>= 2.7.1)
|
23
|
+
net-imap
|
24
|
+
net-pop
|
25
|
+
net-smtp
|
26
|
+
actionmailer (7.0.4.3)
|
27
|
+
actionpack (= 7.0.4.3)
|
28
|
+
actionview (= 7.0.4.3)
|
29
|
+
activejob (= 7.0.4.3)
|
30
|
+
activesupport (= 7.0.4.3)
|
31
|
+
mail (~> 2.5, >= 2.5.4)
|
32
|
+
net-imap
|
33
|
+
net-pop
|
34
|
+
net-smtp
|
35
|
+
rails-dom-testing (~> 2.0)
|
36
|
+
actionpack (7.0.4.3)
|
37
|
+
actionview (= 7.0.4.3)
|
38
|
+
activesupport (= 7.0.4.3)
|
39
|
+
rack (~> 2.0, >= 2.2.0)
|
40
|
+
rack-test (>= 0.6.3)
|
41
|
+
rails-dom-testing (~> 2.0)
|
42
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
43
|
+
actiontext (7.0.4.3)
|
44
|
+
actionpack (= 7.0.4.3)
|
45
|
+
activerecord (= 7.0.4.3)
|
46
|
+
activestorage (= 7.0.4.3)
|
47
|
+
activesupport (= 7.0.4.3)
|
48
|
+
globalid (>= 0.6.0)
|
49
|
+
nokogiri (>= 1.8.5)
|
50
|
+
actionview (7.0.4.3)
|
51
|
+
activesupport (= 7.0.4.3)
|
52
|
+
builder (~> 3.1)
|
53
|
+
erubi (~> 1.4)
|
54
|
+
rails-dom-testing (~> 2.0)
|
55
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
56
|
+
activejob (7.0.4.3)
|
57
|
+
activesupport (= 7.0.4.3)
|
58
|
+
globalid (>= 0.3.6)
|
59
|
+
activemodel (7.0.4.3)
|
60
|
+
activesupport (= 7.0.4.3)
|
61
|
+
activerecord (7.0.4.3)
|
62
|
+
activemodel (= 7.0.4.3)
|
63
|
+
activesupport (= 7.0.4.3)
|
64
|
+
activestorage (7.0.4.3)
|
65
|
+
actionpack (= 7.0.4.3)
|
66
|
+
activejob (= 7.0.4.3)
|
67
|
+
activerecord (= 7.0.4.3)
|
68
|
+
activesupport (= 7.0.4.3)
|
69
|
+
marcel (~> 1.0)
|
70
|
+
mini_mime (>= 1.1.0)
|
71
|
+
activesupport (7.0.4.3)
|
72
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
73
|
+
i18n (>= 1.6, < 2)
|
74
|
+
minitest (>= 5.1)
|
75
|
+
tzinfo (~> 2.0)
|
76
|
+
aws-eventstream (1.2.0)
|
77
|
+
aws-partitions (1.752.0)
|
78
|
+
aws-sdk-core (3.171.0)
|
79
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
80
|
+
aws-partitions (~> 1, >= 1.651.0)
|
81
|
+
aws-sigv4 (~> 1.5)
|
82
|
+
jmespath (~> 1, >= 1.6.1)
|
83
|
+
aws-sdk-sqs (1.53.0)
|
84
|
+
aws-sdk-core (~> 3, >= 3.165.0)
|
85
|
+
aws-sigv4 (~> 1.1)
|
86
|
+
aws-sdk-ssm (1.150.0)
|
87
|
+
aws-sdk-core (~> 3, >= 3.165.0)
|
88
|
+
aws-sigv4 (~> 1.1)
|
89
|
+
aws-sigv4 (1.5.2)
|
90
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
91
|
+
builder (3.2.4)
|
92
|
+
coderay (1.1.3)
|
93
|
+
concurrent-ruby (1.2.2)
|
94
|
+
crass (1.0.6)
|
95
|
+
date (3.3.3)
|
96
|
+
erubi (1.12.0)
|
97
|
+
globalid (1.1.0)
|
98
|
+
activesupport (>= 5.0)
|
99
|
+
i18n (1.12.0)
|
100
|
+
concurrent-ruby (~> 1.0)
|
101
|
+
jmespath (1.6.2)
|
102
|
+
lambda-console-ruby (1.0.0)
|
103
|
+
lambdakiq (2.2.0)
|
104
|
+
activejob
|
105
|
+
aws-sdk-sqs
|
106
|
+
concurrent-ruby
|
107
|
+
railties
|
108
|
+
loofah (2.20.0)
|
109
|
+
crass (~> 1.0.2)
|
110
|
+
nokogiri (>= 1.5.9)
|
111
|
+
mail (2.8.1)
|
112
|
+
mini_mime (>= 0.1.1)
|
113
|
+
net-imap
|
114
|
+
net-pop
|
115
|
+
net-smtp
|
116
|
+
marcel (1.0.2)
|
117
|
+
method_source (1.0.0)
|
118
|
+
mini_mime (1.1.2)
|
119
|
+
minitest (5.18.0)
|
120
|
+
minitest-focus (1.3.1)
|
121
|
+
minitest (>= 4, < 6)
|
122
|
+
mocha (2.0.2)
|
123
|
+
ruby2_keywords (>= 0.0.5)
|
124
|
+
net-imap (0.3.4)
|
125
|
+
date
|
126
|
+
net-protocol
|
127
|
+
net-pop (0.1.2)
|
128
|
+
net-protocol
|
129
|
+
net-protocol (0.2.1)
|
130
|
+
timeout
|
131
|
+
net-smtp (0.3.3)
|
132
|
+
net-protocol
|
133
|
+
nio4r (2.5.9)
|
134
|
+
nokogiri (1.14.3-aarch64-linux)
|
135
|
+
racc (~> 1.4)
|
136
|
+
nokogiri (1.14.3-arm64-darwin)
|
137
|
+
racc (~> 1.4)
|
138
|
+
pry (0.14.2)
|
139
|
+
coderay (~> 1.1)
|
140
|
+
method_source (~> 1.0)
|
141
|
+
racc (1.6.2)
|
142
|
+
rack (2.2.6.4)
|
143
|
+
rack-test (2.1.0)
|
144
|
+
rack (>= 1.3)
|
145
|
+
rails (7.0.4.3)
|
146
|
+
actioncable (= 7.0.4.3)
|
147
|
+
actionmailbox (= 7.0.4.3)
|
148
|
+
actionmailer (= 7.0.4.3)
|
149
|
+
actionpack (= 7.0.4.3)
|
150
|
+
actiontext (= 7.0.4.3)
|
151
|
+
actionview (= 7.0.4.3)
|
152
|
+
activejob (= 7.0.4.3)
|
153
|
+
activemodel (= 7.0.4.3)
|
154
|
+
activerecord (= 7.0.4.3)
|
155
|
+
activestorage (= 7.0.4.3)
|
156
|
+
activesupport (= 7.0.4.3)
|
157
|
+
bundler (>= 1.15.0)
|
158
|
+
railties (= 7.0.4.3)
|
159
|
+
rails-dom-testing (2.0.3)
|
160
|
+
activesupport (>= 4.2.0)
|
161
|
+
nokogiri (>= 1.6)
|
162
|
+
rails-html-sanitizer (1.5.0)
|
163
|
+
loofah (~> 2.19, >= 2.19.1)
|
164
|
+
railties (7.0.4.3)
|
165
|
+
actionpack (= 7.0.4.3)
|
166
|
+
activesupport (= 7.0.4.3)
|
167
|
+
method_source
|
168
|
+
rake (>= 12.2)
|
169
|
+
thor (~> 1.0)
|
170
|
+
zeitwerk (~> 2.5)
|
171
|
+
rake (13.0.6)
|
172
|
+
ruby2_keywords (0.0.5)
|
173
|
+
thor (1.2.1)
|
174
|
+
timecop (0.9.6)
|
175
|
+
timeout (0.3.2)
|
176
|
+
tzinfo (2.0.6)
|
177
|
+
concurrent-ruby (~> 1.0)
|
178
|
+
webrick (1.8.1)
|
179
|
+
websocket-driver (0.7.5)
|
180
|
+
websocket-extensions (>= 0.1.0)
|
181
|
+
websocket-extensions (0.1.5)
|
182
|
+
zeitwerk (2.6.7)
|
183
|
+
|
184
|
+
PLATFORMS
|
185
|
+
aarch64-linux
|
186
|
+
arm64-darwin-21
|
187
|
+
arm64-darwin-22
|
188
|
+
|
189
|
+
DEPENDENCIES
|
190
|
+
aws-sdk-ssm
|
191
|
+
bundler
|
192
|
+
lambdakiq
|
193
|
+
lamby_updated!
|
194
|
+
minitest
|
195
|
+
minitest-focus
|
196
|
+
mocha
|
197
|
+
pry
|
198
|
+
rails
|
199
|
+
rake
|
200
|
+
timecop
|
201
|
+
webrick
|
202
|
+
|
203
|
+
BUNDLED WITH
|
204
|
+
2.3.26
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Ken Collins
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Lamby [](https://github.com/rails-lambda/lamby/actions)
|
2
|
+
|
3
|
+
<h2>Simple Rails & AWS Lambda Integration using Rack</h2>
|
4
|
+
<a href="https://lamby.cloud"><img src="https://raw.githubusercontent.com/rails-lambda/lamby/master/images/social2.png" alt="Lamby: Simple Rails & AWS Lambda Integration using Rack." align="right" width="450" style="margin-left:1rem;margin-bottom:1rem;" /></a>
|
5
|
+
|
6
|
+
Lamby is an [AWS Lambda Web Adapter](https://github.com/awslabs/aws-lambda-web-adapter) for Rack applications.
|
7
|
+
|
8
|
+
We support Lambda [Function URLs](https://docs.aws.amazon.com/lambda/latest/dg/lambda-urls.html), [API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html) (HTTP or REST, all payload versions), and even [Application Load Balancer](https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html) integrations.
|
9
|
+
|
10
|
+
## Quick Start
|
11
|
+
|
12
|
+
https://lamby.cloud/docs/quick-start
|
13
|
+
|
14
|
+
## Full Documentation
|
15
|
+
|
16
|
+
https://lamby.cloud/docs/anatomy
|
17
|
+
|
18
|
+
## Contributing
|
19
|
+
|
20
|
+
[](https://codespaces.new/rails-lambda/lamby)
|
21
|
+
|
22
|
+
This project is built for [GitHub Codespaces](https://github.com/features/codespaces) using the [Development Container](https://containers.dev) specification. Once you have the repo cloned and setup with a dev container using either Codespaces or [VS Code](#using-vs-code), run the following commands. This will install packages and run tests.
|
23
|
+
|
24
|
+
```shell
|
25
|
+
$ ./bin/setup
|
26
|
+
$ ./bin/test
|
27
|
+
```
|
28
|
+
|
29
|
+
#### Using VS Code
|
30
|
+
|
31
|
+
If you have the [Visual Studio Code Dev Container](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension installed you can easily clone this repo locally, use the "Open Folder in Container..." command. This allows you to use the integrated terminal for the commands above.
|
32
|
+
|
33
|
+
## Code of Conduct
|
34
|
+
|
35
|
+
Everyone interacting in the Lamby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rails-lambda/lamby/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rails-lambda/lamby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
ENV['RUBYOPT'] = '-W:no-deprecated -W:no-experimental'
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rake/testtask"
|
4
|
+
|
5
|
+
Rake::TestTask.new(:test) do |t|
|
6
|
+
t.libs << "test"
|
7
|
+
t.libs << "lib"
|
8
|
+
t.test_files = begin
|
9
|
+
if ENV['TEST_FILE']
|
10
|
+
[ENV['TEST_FILE']]
|
11
|
+
else
|
12
|
+
FileList["test/**/*_test.rb"]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
t.verbose = false
|
16
|
+
t.warning = false
|
17
|
+
end
|
18
|
+
|
19
|
+
Rake::TestTask.new(:test_deflate) do |t|
|
20
|
+
t.libs << "test"
|
21
|
+
t.libs << "lib"
|
22
|
+
t.test_files = FileList["test/rack_deflate_test.rb"]
|
23
|
+
t.verbose = false
|
24
|
+
t.warning = false
|
25
|
+
end
|
26
|
+
|
27
|
+
task :default => [:test, :test_deflate]
|
data/bin/bootstrap
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "lamby"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/bin/test
ADDED
data/bin/update
ADDED
data/images/social.png
ADDED
Binary file
|
data/images/social2.png
ADDED
Binary file
|
data/lamby.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lamby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lamby_updated"
|
8
|
+
spec.version = Lamby::VERSION
|
9
|
+
spec.authors = ["Ken Collins"]
|
10
|
+
spec.email = ["ken@metaskills.net"]
|
11
|
+
spec.summary = %q{Simple Rails & AWS Lambda Integration using Rack}
|
12
|
+
spec.description = %q{Simple Rails & AWS Lambda Integration using Rack and various utilities.}
|
13
|
+
spec.homepage = "https://github.com/rails-lambda/lamby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
16
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
spec.add_dependency 'rack'
|
22
|
+
spec.add_dependency 'lambda-console-ruby'
|
23
|
+
spec.add_development_dependency 'aws-sdk-ssm'
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'minitest'
|
27
|
+
spec.add_development_dependency 'minitest-focus'
|
28
|
+
spec.add_development_dependency 'mocha'
|
29
|
+
spec.add_development_dependency 'pry'
|
30
|
+
spec.add_development_dependency 'timecop'
|
31
|
+
spec.add_development_dependency 'webrick'
|
32
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Lamby
|
2
|
+
class ColdStartMetrics
|
3
|
+
NAMESPACE = 'Lamby'
|
4
|
+
|
5
|
+
@cold_start = true
|
6
|
+
@cold_start_time = (Time.now.to_f * 1000).to_i
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def instrument!
|
11
|
+
return unless @cold_start
|
12
|
+
@cold_start = false
|
13
|
+
now = (Time.now.to_f * 1000).to_i
|
14
|
+
proactive_init = (now - @cold_start_time) > 10_000
|
15
|
+
new(proactive_init).instrument!
|
16
|
+
end
|
17
|
+
|
18
|
+
def clear!
|
19
|
+
@cold_start = true
|
20
|
+
@cold_start_time = (Time.now.to_f * 1000).to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(proactive_init)
|
26
|
+
@proactive_init = proactive_init
|
27
|
+
@metrics = []
|
28
|
+
@properties = {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def instrument!
|
32
|
+
name = @proactive_init ? 'ProactiveInit' : 'ColdStart'
|
33
|
+
put_metric name, 1, 'Count'
|
34
|
+
puts JSON.dump(message)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def dimensions
|
40
|
+
[{ AppName: rails_app_name }]
|
41
|
+
end
|
42
|
+
|
43
|
+
def put_metric(name, value, unit = nil)
|
44
|
+
@metrics << { 'Name': name }.tap do |m|
|
45
|
+
m['Unit'] = unit if unit
|
46
|
+
end
|
47
|
+
set_property name, value
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_property(name, value)
|
51
|
+
@properties[name] = value
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
def message
|
56
|
+
{
|
57
|
+
'_aws': {
|
58
|
+
'Timestamp': timestamp,
|
59
|
+
'CloudWatchMetrics': [
|
60
|
+
{
|
61
|
+
'Namespace': NAMESPACE,
|
62
|
+
'Dimensions': [dimensions.map(&:keys).flatten],
|
63
|
+
'Metrics': @metrics
|
64
|
+
}
|
65
|
+
]
|
66
|
+
}
|
67
|
+
}.tap do |m|
|
68
|
+
dimensions.each { |d| m.merge!(d) }
|
69
|
+
m.merge!(@properties)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def timestamp
|
74
|
+
Time.current.strftime('%s%3N').to_i
|
75
|
+
end
|
76
|
+
|
77
|
+
def rails_app_name
|
78
|
+
Lamby.config.metrics_app_name ||
|
79
|
+
Rails.application.class.name.split('::').first
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
data/lib/lamby/config.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
module Lamby
|
2
|
+
module Config
|
3
|
+
|
4
|
+
def configure
|
5
|
+
yield(config)
|
6
|
+
config
|
7
|
+
end
|
8
|
+
|
9
|
+
def reconfigure
|
10
|
+
config.reconfigure { |c| yield(c) if block_given? }
|
11
|
+
end
|
12
|
+
|
13
|
+
def config
|
14
|
+
@config ||= Configuration.new
|
15
|
+
end
|
16
|
+
|
17
|
+
extend self
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class Configuration
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
initialize_defaults
|
25
|
+
end
|
26
|
+
|
27
|
+
def reconfigure
|
28
|
+
instance_variables.each { |var| instance_variable_set var, nil }
|
29
|
+
initialize_defaults
|
30
|
+
yield(self) if block_given?
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def rack_app
|
35
|
+
@rack_app ||= ::Rack::Builder.new { run ::Rails.application }.to_app
|
36
|
+
end
|
37
|
+
|
38
|
+
def rack_app=(app)
|
39
|
+
@rack_app = app
|
40
|
+
end
|
41
|
+
|
42
|
+
def initialize_defaults
|
43
|
+
@rack_app = nil
|
44
|
+
@cold_start_metrics = false
|
45
|
+
@metrics_app_name = nil
|
46
|
+
@event_bridge_handler = lambda { |event, context| puts(event) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def event_bridge_handler
|
50
|
+
@event_bridge_handler
|
51
|
+
end
|
52
|
+
|
53
|
+
def event_bridge_handler=(func)
|
54
|
+
@event_bridge_handler = func
|
55
|
+
end
|
56
|
+
|
57
|
+
def runner_patterns
|
58
|
+
LambdaConsole::Run::PATTERNS
|
59
|
+
end
|
60
|
+
|
61
|
+
def handled_proc
|
62
|
+
@handled_proc ||= Proc.new { |_event, _context| }
|
63
|
+
end
|
64
|
+
|
65
|
+
def handled_proc=(proc)
|
66
|
+
@handled_proc = proc
|
67
|
+
end
|
68
|
+
|
69
|
+
def cold_start_metrics?
|
70
|
+
@cold_start_metrics
|
71
|
+
end
|
72
|
+
|
73
|
+
def cold_start_metrics=(bool)
|
74
|
+
@cold_start_metrics = bool
|
75
|
+
end
|
76
|
+
|
77
|
+
def metrics_app_name
|
78
|
+
@metrics_app_name
|
79
|
+
end
|
80
|
+
|
81
|
+
def metrics_app_name=(name)
|
82
|
+
@metrics_app_name = name
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
data/lib/lamby/debug.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Lamby
|
2
|
+
module Debug
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def on?(event)
|
6
|
+
params = event['multiValueQueryStringParameters'] || event['queryStringParameters']
|
7
|
+
(development? || ENV['LAMBY_DEBUG']) && params && params['debug'] == '1'
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(event, context, env)
|
11
|
+
[ 200, { 'Content-Type' => 'text/html' }, [body(event, context, env)] ]
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def body(event, context, env)
|
17
|
+
<<-HTML
|
18
|
+
<!DOCTYPE html>
|
19
|
+
<html>
|
20
|
+
<body>
|
21
|
+
<h1>Lamby Debug Response</h1>
|
22
|
+
<h2>Event</h2>
|
23
|
+
<pre>
|
24
|
+
#{JSON.pretty_generate(event)}
|
25
|
+
</pre>
|
26
|
+
<h2>Rack Env</h2>
|
27
|
+
<pre>
|
28
|
+
#{JSON.pretty_generate(env)}
|
29
|
+
</pre>
|
30
|
+
<h2>#{context.class.name}</h2>
|
31
|
+
<code>
|
32
|
+
#{CGI::escapeHTML(context.inspect)}
|
33
|
+
</code>
|
34
|
+
</body>
|
35
|
+
</html>
|
36
|
+
HTML
|
37
|
+
end
|
38
|
+
|
39
|
+
def development?
|
40
|
+
ENV.to_h
|
41
|
+
.slice('RACK_ENV', 'RAILS_ENV')
|
42
|
+
.values
|
43
|
+
.any? { |v| v.to_s.casecmp('development').zero? }
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|