https://github.com/elct9620/hanami-lambda
Hanami Lambda is a gem that provides a way to run hanami application on AWS Lambda.
https://github.com/elct9620/hanami-lambda
hanami lambda
Last synced: 5 months ago
JSON representation
Hanami Lambda is a gem that provides a way to run hanami application on AWS Lambda.
- Host: GitHub
- URL: https://github.com/elct9620/hanami-lambda
- Owner: elct9620
- License: mit
- Created: 2024-01-01T08:09:03.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-23T07:06:16.000Z (9 months ago)
- Last Synced: 2025-04-30T14:18:51.786Z (5 months ago)
- Topics: hanami, lambda
- Language: Ruby
- Homepage:
- Size: 87.9 KB
- Stars: 4
- Watchers: 2
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
Hanami::Lambda
===Hanami Lambda is a gem that provides a way to run hanami application on AWS Lambda.
## Status
[](https://badge.fury.io/rb/hanami-lambda)
[](https://github.com/elct9620/hanami-lambda/actions/workflows/main.yml)## Rubies
**Hanami::Lambda** supports Ruby (MRI) 3.0+
## Installation
Add this line to your application's Gemfile:
```ruby
gem "hanami-lambda"
```And then execute:
```
$ bundle install
```Update `config/app.rb` with below content
```ruby
require 'hanami'
require 'hanami/lambda'module MyApp # Rename to your app name
class Lambda < Hanami::App
extend Hanami::Lambda::Application
end
end
```Create `app/function.rb` as handler base class
```ruby
module MyApp
class Function < Hanami::Lambda::Function
end
end
```> Generator is comming soon.
## Usage
Use `config/app.Hanami::Lambda.call` as the function handler
```yaml
# AWS SAM
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: config/app.Hanami::Lambda.call
Runtime: ruby3.2
```### Delegate
If the lambda function isn't trigger by APIGateway, we can use `delegate` method to define the handler function.
Create `config/lambda.rb` with below content
```ruby
module MyApp
class Lambda < Hanami::Lambda::Dispatcher
delegate "MyFunction", to: "daily_task"
end
end
```> The IaC generated function will be `my-app-MyFunction-r8faNAo3iUqx` therefore the dispatcher will use include `MyFunction` to find targeted function
Add `app/functions/daily_task.rb` to define the handle action
```ruby
module MyApp
module Functions
class DailyTask < MyApp::Function
def handle(event, context)
# ...
end
end
end
end
```## Development
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.
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).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/elct9620/hanami-lambda.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).