yake 0.4.1 → 0.4.2
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 +4 -4
- data/README.md +47 -21
- data/lib/yake/dsl.rb +2 -1
- data/lib/yake/logger.rb +12 -5
- data/lib/yake/version.rb +1 -1
- metadata +2 -3
- data/LICENSE.txt +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 224ba56816d47b87e5691c7d95904807b9754b6df437fa85a23e8c3190534c8c
|
4
|
+
data.tar.gz: de423580d089fd5879788cd6491daeb30012adcdc9ae7ff6d666a090e8bf73a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d270d5b7eb530917d3d7f2e0ddd2e847fd40300215366f22aa4dd67808f84c028172be6e3f8c9a2894a192a527cbbb361c2ab346b17e4b90ec02ec72d8865fa1
|
7
|
+
data.tar.gz: 23120b48ee291d9698b83cad68f4d54ebc5abbb99ba72ed3f01af1d3f36a4a7ac72f20e5b468e290c9ed7995d3a9d541e9f07b2d52e254afd716317f3b9794d4
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ Write your AWS Lambda function handlers using a Rake-like declarative syntax:
|
|
9
9
|
|
10
10
|
```ruby
|
11
11
|
# ./lambda_function.rb
|
12
|
-
require
|
12
|
+
require 'yake'
|
13
13
|
|
14
14
|
handler :lambda_handler do |event|
|
15
15
|
# Your code here
|
@@ -22,11 +22,11 @@ You can even declare Sinatra-like API Gateway routes for a main entrypoint:
|
|
22
22
|
|
23
23
|
```ruby
|
24
24
|
# ./lambda_function.rb
|
25
|
-
require
|
25
|
+
require 'yake/api'
|
26
26
|
|
27
|
-
header
|
27
|
+
header 'content-type' => 'application/json'
|
28
28
|
|
29
|
-
get
|
29
|
+
get '/fizz' do
|
30
30
|
respond 200, { ok: true }.to_json
|
31
31
|
end
|
32
32
|
|
@@ -44,7 +44,7 @@ end
|
|
44
44
|
Add this line to your application's Gemfile:
|
45
45
|
|
46
46
|
```ruby
|
47
|
-
gem
|
47
|
+
gem 'yake'
|
48
48
|
```
|
49
49
|
|
50
50
|
And then execute:
|
@@ -82,10 +82,12 @@ REPORT RequestId: 149c500f-028a-4b57-8977-0ef568cf8caf Duration: 43.97 ms Billed
|
|
82
82
|
|
83
83
|
Logging the request ID in this way makes gathering logs lines for a particular execution in CloudWatch much easier.
|
84
84
|
|
85
|
-
|
85
|
+
You can or disable the logger:
|
86
86
|
|
87
87
|
```ruby
|
88
|
-
logging :off
|
88
|
+
logging :off # disables logging entirely
|
89
|
+
logging pretty: false # Logs event/result in compact JSON
|
90
|
+
logging :on, MyLogger.new # Use a custom logger
|
89
91
|
```
|
90
92
|
|
91
93
|
Include `Yake::Logger` on a class to access this logger:
|
@@ -108,35 +110,35 @@ Requiring the `yake/api` module will add the API-specific DSL into your handler.
|
|
108
110
|
Define API routes using Sinatra-like syntax
|
109
111
|
|
110
112
|
```ruby
|
111
|
-
any
|
113
|
+
any '/…' do |event|
|
112
114
|
# Handle 'ANY /…' route key events
|
113
115
|
end
|
114
116
|
|
115
|
-
delete
|
117
|
+
delete '/…' do |event|
|
116
118
|
# Handle 'DELETE /…' route key events
|
117
119
|
end
|
118
120
|
|
119
|
-
get
|
121
|
+
get '/…' do |event|
|
120
122
|
# Handle 'GET /…' route key events
|
121
123
|
end
|
122
124
|
|
123
|
-
head
|
125
|
+
head '/…' do |event|
|
124
126
|
# Handle 'HEAD /…' route key events
|
125
127
|
end
|
126
128
|
|
127
|
-
options
|
129
|
+
options '/…' do |event|
|
128
130
|
# Handle 'OPTIONS /…' route key events
|
129
131
|
end
|
130
132
|
|
131
|
-
patch
|
133
|
+
patch '/…' do |event|
|
132
134
|
# Handle 'PATCH /…' route key events
|
133
135
|
end
|
134
136
|
|
135
|
-
post
|
137
|
+
post '/…' do |event|
|
136
138
|
# Handle 'POST /…' route key events
|
137
139
|
end
|
138
140
|
|
139
|
-
put
|
141
|
+
put '/…' do |event|
|
140
142
|
# Handle 'PUT /…' route key events
|
141
143
|
end
|
142
144
|
```
|
@@ -146,14 +148,14 @@ Helper methods are also made available to help produce a response for API Gatewa
|
|
146
148
|
Set a default header for ALL responses:
|
147
149
|
|
148
150
|
```ruby
|
149
|
-
header
|
150
|
-
header
|
151
|
+
header 'content-type' => 'application/json; charset=utf-8'
|
152
|
+
header 'x-custom-header' => 'fizz'
|
151
153
|
```
|
152
154
|
|
153
155
|
Produce an API Gateway-style response object:
|
154
156
|
|
155
157
|
```ruby
|
156
|
-
respond 200, { ok: true }.to_json,
|
158
|
+
respond 200, { ok: true }.to_json, 'x-extra-header' => 'buzz'
|
157
159
|
# {
|
158
160
|
# "statusCode" => 200,
|
159
161
|
# "body" => '{"ok":true}',
|
@@ -177,11 +179,35 @@ end
|
|
177
179
|
|
178
180
|
Finally, `yake` does not depend on any other gems, using the Ruby stdlib only. This helps keep your Lambda packages slim & speedy.
|
179
181
|
|
180
|
-
##
|
182
|
+
## Datadog Integration
|
183
|
+
|
184
|
+
As of `~> 0.4`, `yake` comes with a helper for writing Lambdas that integrate with Datadog's `datadog-ruby` gem.
|
181
185
|
|
182
|
-
|
186
|
+
Creating a Lambda handler that wraps the Datadog tooling is easy:
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
require 'aws-sdk-someservice'
|
190
|
+
require 'yake/datadog'
|
191
|
+
|
192
|
+
# Configure Datadog to use AWS tracing
|
193
|
+
Datadog::Lambda.configure_apm { |config| config.use :aws }
|
194
|
+
|
195
|
+
datadog :handler do |event|
|
196
|
+
# …
|
197
|
+
end
|
198
|
+
```
|
199
|
+
|
200
|
+
## Deployment
|
201
|
+
|
202
|
+
After writing your Lambda handler code you can deploy it to AWS using any number of tools. I recommend the following tools:
|
203
|
+
|
204
|
+
- [Terraform](https://www.terraform.io) — my personal favorite Infrastructure-as-Code tool
|
205
|
+
- [AWS SAM](https://aws.amazon.com/serverless/sam/) — a great alternative with less configuration than Terraform
|
206
|
+
- [Serverless](https://www.serverless.com) — Supposedly the most popular option, though I have not used it
|
207
|
+
|
208
|
+
## Development
|
183
209
|
|
184
|
-
|
210
|
+
After checking out the repo, run `bundle` to install dependencies. Then, run `rake spec` to run the tests.
|
185
211
|
|
186
212
|
## Contributing
|
187
213
|
|
data/lib/yake/dsl.rb
CHANGED
data/lib/yake/logger.rb
CHANGED
@@ -5,7 +5,7 @@ require 'logger'
|
|
5
5
|
|
6
6
|
module Yake
|
7
7
|
module Logger
|
8
|
-
|
8
|
+
attr_writer :logger
|
9
9
|
|
10
10
|
def logger
|
11
11
|
@logger ||= Yake.logger
|
@@ -27,17 +27,24 @@ module Yake
|
|
27
27
|
end
|
28
28
|
|
29
29
|
class << self
|
30
|
-
|
30
|
+
attr_writer :logger, :pretty
|
31
31
|
|
32
32
|
def logger
|
33
33
|
@logger ||= Logger.new
|
34
34
|
end
|
35
35
|
|
36
|
+
def pretty?
|
37
|
+
@pretty != false
|
38
|
+
end
|
39
|
+
|
36
40
|
def wrap(event = nil, context = nil, &block)
|
37
41
|
original_progname = logger.progname
|
38
|
-
logger.progname
|
39
|
-
|
40
|
-
|
42
|
+
logger.progname = context&.aws_request_id
|
43
|
+
jsonify = -> (obj) { pretty? ? JSON.pretty_generate(obj) : obj.to_json }
|
44
|
+
logger.info("EVENT #{ jsonify === event }")
|
45
|
+
yield(event, context).tap do |res|
|
46
|
+
logger.info("RETURN #{ jsonify === res }")
|
47
|
+
end
|
41
48
|
ensure
|
42
49
|
logger.progname = original_progname
|
43
50
|
end
|
data/lib/yake/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Mancevice
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -18,7 +18,6 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- LICENSE
|
21
|
-
- LICENSE.txt
|
22
21
|
- README.md
|
23
22
|
- lib/yake.rb
|
24
23
|
- lib/yake/api.rb
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2021 Alexander Mancevice
|
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.
|