hanami-lambda 0.1.0
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/.rspec +3 -0
- data/.rubocop.yml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +71 -0
- data/Rakefile +12 -0
- data/lib/hanami/lambda/application.rb +37 -0
- data/lib/hanami/lambda/rack.rb +49 -0
- data/lib/hanami/lambda/version.rb +7 -0
- data/lib/hanami/lambda.rb +70 -0
- data/lib/hanami-lambda.rb +3 -0
- data/sig/hanami/lambda.rbs +6 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e6434425a9bc1477663be14851eb304da6fd9fc5ebe9a9ff3b800afb72986f1d
|
4
|
+
data.tar.gz: 94b184c7584379f57d7214c24e4963e3ca2b66d9a5cac02781e6612254f868a3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 296484573f0c74479a2f3ddf78f4eef69c8d41e7ae34eae2bc18055aaa17c7d9ad49f843f016555a08c72743272d237e289d64dba5aadc8a7dcb696f9e07d5a4
|
7
|
+
data.tar.gz: d8b969b733db865b342cb55a9e800020ed416922db7061115ff36cb4d391bc76ff78d83f4e49e731e40c512a41ebda80b416d3bece37c559429eba5fed29b507
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Aotokitsuruya
|
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,71 @@
|
|
1
|
+
Hanami::Lambda
|
2
|
+
===
|
3
|
+
|
4
|
+
Hanami Lambda is a gem that provides a way to run hanami application on AWS Lambda.
|
5
|
+
|
6
|
+
## Status
|
7
|
+
|
8
|
+
[](https://badge.fury.io/rb/hanami-lambda)
|
9
|
+
[](https://github.com/elct9620/hanami-lambda/actions/workflows/main.yml)
|
10
|
+
|
11
|
+
## Rubies
|
12
|
+
|
13
|
+
**Hanami::Cucumber** supports Ruby (MRI) 3.0+
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem "hanami-lambda"
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
```
|
26
|
+
$ bundle install
|
27
|
+
```
|
28
|
+
|
29
|
+
Create `config/lambda.rb` with below content
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'hanami/lambda'
|
33
|
+
|
34
|
+
module MyApp # Rename to your app name
|
35
|
+
class Lambda < Hanami::Lambda::Application
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
> Generator is comming soon.
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
Use `config/lambda.Hanami::Lambda.call` as the function handler
|
45
|
+
|
46
|
+
```yaml
|
47
|
+
Resources:
|
48
|
+
ExampleHandler:
|
49
|
+
Type: AWS::Serverless::Function
|
50
|
+
Name: "example-api"
|
51
|
+
Properties:
|
52
|
+
CodeUri: .
|
53
|
+
Handler: config/lambda.Hanami::Lambda.call
|
54
|
+
Runtime: ruby3.2
|
55
|
+
```
|
56
|
+
|
57
|
+
> Currently, the only `APIGateWay` event is supported
|
58
|
+
|
59
|
+
## Development
|
60
|
+
|
61
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
62
|
+
|
63
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/elct9620/hanami-lambda.
|
68
|
+
|
69
|
+
## License
|
70
|
+
|
71
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hanami
|
4
|
+
module Lambda
|
5
|
+
# The application to configure for AWS Lambda.
|
6
|
+
#
|
7
|
+
# @since 0.1.0
|
8
|
+
class Application
|
9
|
+
# @api private
|
10
|
+
def self.inherited(subclass)
|
11
|
+
super
|
12
|
+
|
13
|
+
Hanami::Lambda.app = subclass
|
14
|
+
subclass.extend(ClassMethods)
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
# Dispatch event to the handler
|
19
|
+
#
|
20
|
+
# @api private
|
21
|
+
# @since 0.1.0
|
22
|
+
def call(event:, context:)
|
23
|
+
handler = lookup(event: event, context: context)
|
24
|
+
handler.call
|
25
|
+
end
|
26
|
+
|
27
|
+
# Lookup the handler for the given event
|
28
|
+
#
|
29
|
+
# @api private
|
30
|
+
# @since 0.1.0
|
31
|
+
def lookup(event:, context:)
|
32
|
+
Rack.new(Hanami.app, event: event, context: context)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hanami
|
4
|
+
module Lambda
|
5
|
+
# Rack interface for AWS Lambda.
|
6
|
+
#
|
7
|
+
# @api private
|
8
|
+
# @since 0.1.0
|
9
|
+
class Rack
|
10
|
+
attr_reader :app, :event, :context
|
11
|
+
|
12
|
+
# @api private
|
13
|
+
def initialize(app, event:, context:)
|
14
|
+
@app = app
|
15
|
+
@event = event
|
16
|
+
@context = context
|
17
|
+
end
|
18
|
+
|
19
|
+
# Handle the request
|
20
|
+
#
|
21
|
+
# @return [Hash] the response
|
22
|
+
#
|
23
|
+
# @since 0.1.0
|
24
|
+
def call
|
25
|
+
status_code, headers, body = app.call(env)
|
26
|
+
|
27
|
+
{
|
28
|
+
statusCode: status_code,
|
29
|
+
headers: headers,
|
30
|
+
body: body.join
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
# Build the Rack environment
|
35
|
+
#
|
36
|
+
# @return [Hash] the Rack environment
|
37
|
+
#
|
38
|
+
# @since 0.1.0
|
39
|
+
def env
|
40
|
+
{
|
41
|
+
::Rack::REQUEST_METHOD => event["httpMethod"],
|
42
|
+
::Rack::PATH_INFO => event["path"] || "",
|
43
|
+
::Rack::VERSION => ::Rack::VERSION,
|
44
|
+
::Rack::RACK_INPUT => StringIO.new(event["body"] || "")
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "zeitwerk"
|
4
|
+
|
5
|
+
# @see Hanami::Lambda
|
6
|
+
# @since 0.1.0
|
7
|
+
module Hanami
|
8
|
+
# Make Hanami can be run on AWS Lambda.
|
9
|
+
#
|
10
|
+
# @since 0.1.0
|
11
|
+
# @api private
|
12
|
+
module Lambda
|
13
|
+
@_mutex = Mutex.new
|
14
|
+
|
15
|
+
# Returns the Hanami::Lambda application.
|
16
|
+
#
|
17
|
+
# @return [Hanami::Lambda::Application] the application
|
18
|
+
# @raise [Hanami::AppLoadError] if the application isn't configured
|
19
|
+
#
|
20
|
+
# @api public
|
21
|
+
# @since 0.1.0
|
22
|
+
def self.app
|
23
|
+
@_mutex.synchronize do
|
24
|
+
unless defined?(@_app)
|
25
|
+
raise Hanami::AppLoadError,
|
26
|
+
"Hanami::Lambda.app is not yet configured. "
|
27
|
+
end
|
28
|
+
|
29
|
+
@_app
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# @api private
|
34
|
+
# @since 0.1.0
|
35
|
+
def self.app=(klass)
|
36
|
+
@_mutex.synchronize do
|
37
|
+
raise AppLoadError, "Hanami::Lambda.app is already configured." if instance_variable_defined?(:@_app)
|
38
|
+
|
39
|
+
@_app = klass unless klass.name.nil?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.call(event:, context:)
|
44
|
+
require "hanami/setup"
|
45
|
+
|
46
|
+
Hanami.boot
|
47
|
+
app.call(event: event, context: context)
|
48
|
+
end
|
49
|
+
|
50
|
+
# @since 0.1.0
|
51
|
+
# @api private
|
52
|
+
def self.gem_loader
|
53
|
+
@gem_loader ||= Zeitwerk::Loader.new.tap do |loader|
|
54
|
+
root = File.expand_path("..", __dir__)
|
55
|
+
loader.tag = "hanami-lambda"
|
56
|
+
loader.inflector = Zeitwerk::GemInflector.new("#{root}/hanami-lambda.rb")
|
57
|
+
loader.push_dir(root)
|
58
|
+
loader.ignore(
|
59
|
+
"#{root}/hanami-lambda.rb",
|
60
|
+
"#{root}/hanami/lambda/{rake_tasks,version}.rb",
|
61
|
+
"#{root}/hanami/lambda/support"
|
62
|
+
)
|
63
|
+
loader.inflector.inflect("lambda" => "Lambda")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
gem_loader.setup
|
68
|
+
require_relative "lambda/version"
|
69
|
+
end
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hanami-lambda
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aotokitsuruya
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-01-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: zeitwerk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.59'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.59'
|
41
|
+
description: Hanami Lambda is a gem that provides a way to run hanami application
|
42
|
+
on AWS Lambda.
|
43
|
+
email:
|
44
|
+
- contact@aotoki.me
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".rspec"
|
50
|
+
- ".rubocop.yml"
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/hanami-lambda.rb
|
55
|
+
- lib/hanami/lambda.rb
|
56
|
+
- lib/hanami/lambda/application.rb
|
57
|
+
- lib/hanami/lambda/rack.rb
|
58
|
+
- lib/hanami/lambda/version.rb
|
59
|
+
- sig/hanami/lambda.rbs
|
60
|
+
homepage: https://github.com/elct9620/hanami-lambda
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata:
|
64
|
+
allowed_push_host: https://rubygems.org
|
65
|
+
homepage_uri: https://github.com/elct9620/hanami-lambda
|
66
|
+
source_code_uri: https://github.com/elct9620/hanami-lambda
|
67
|
+
changelog_uri: https://github.com/elct9620/hanami-lambda/blob/main/CHANGELOG.md
|
68
|
+
rubygems_mfa_required: 'true'
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 3.0.0
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubygems_version: 3.5.3
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Hanami Lambda
|
88
|
+
test_files: []
|