{"id":20453324,"url":"https://github.com/umihico/serverless-rails-demo","last_synced_at":"2026-05-18T04:11:52.910Z","repository":{"id":96444741,"uuid":"435286852","full_name":"umihico/serverless-rails-demo","owner":"umihico","description":"Ruby on Rails hosted on AWS Lambda with smallest modification","archived":false,"fork":false,"pushed_at":"2021-12-13T04:54:37.000Z","size":144,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-15T23:15:53.094Z","etag":null,"topics":["aws-lambda","rails","ruby-on-rails","serverless"],"latest_commit_sha":null,"homepage":"https://fxkgpsdpvl.execute-api.ap-northeast-1.amazonaws.com/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/umihico.png","metadata":{"files":{"readme":"README.jp.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-05T21:48:03.000Z","updated_at":"2023-05-12T17:11:43.000Z","dependencies_parsed_at":"2023-06-26T02:06:46.456Z","dependency_job_id":null,"html_url":"https://github.com/umihico/serverless-rails-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umihico%2Fserverless-rails-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umihico%2Fserverless-rails-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umihico%2Fserverless-rails-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umihico%2Fserverless-rails-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/umihico","download_url":"https://codeload.github.com/umihico/serverless-rails-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242005737,"owners_count":20056432,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-lambda","rails","ruby-on-rails","serverless"],"created_at":"2024-11-15T11:12:29.133Z","updated_at":"2025-10-12T21:01:48.082Z","avatar_url":"https://github.com/umihico.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Railsのサーバーレス化を最小手順でやるデモ\n\nRailsのサーバーレスで動かす代表的な方法としてJetsやLambyなどがあります。またSinatraではありますがAWSは[公式サンプル](https://raw.githubusercontent.com/aws-samples/serverless-sinatra-sample)を提供するようになりました。\n\nこの記事はそれよりももっと手軽に、最小の改変でLambdaにデプロイするにはどうすればよいか試してみた記事になります。結論としては数ファイルの設置と数カ所の変更だけでRailsのサーバーレス化は可能でした。[こちらが試しに作ったURLです。](https://fxkgpsdpvl.execute-api.ap-northeast-1.amazonaws.com/)\n\n以下は新規プロジェクトの場合の実演です。[レポジトリはこちらです。](https://github.com/umihico/serverless-rails-demo)今回もServerless Frameworkを使います。\n\n1. 以下の４ファイルを置く (1stコミット)\n\n   - [.dockerignore](https://github.com/umihico/serverless-rails-demo/blob/master/.dockerignore)\n   - [Dockerfile](https://github.com/umihico/serverless-rails-demo/blob/master/Dockerfile)\n   - [init.sh](https://github.com/umihico/serverless-rails-demo/blob/master/init.sh)\n   - [serverless.yml](https://github.com/umihico/serverless-rails-demo/blob/master/serverless.yml)\n\n2. init.shを実行する。 (2ndコミット). `rails new .`が中で実行され初期の構成ファイルが生成されます。\n\n3. Sinatraの公式サンプルから[このファイル](https://raw.githubusercontent.com/aws-samples/serverless-sinatra-sample/71c8e849a619a8fea169e328b93a7434054e86fa/lambda.rb)をダウンロードします。(3rdコミット)\n\n4. 以下のファイルを改変します。 (4stコミット)\n\n   - config.ruのパスに合わせ修正\n   - サンプルはAPI GatewayのREST API対応なので、HTTP APIに合うように修正\n   - `/tmp`以下以外の書き込みが不可なので、またCouldwatchで見れるようロギング設定を標準出力に変える\n   - Serverless Frameworkに合わせ.gitignore追加\n   - 任意ですが開発中は生リクエスト情報見たいので標準出力に書き出す\n\n5. 後述のわけあってproductionとしてデプロイしてますが、welcomeページ消えるので追加 (5thコミット)\n\n6. 次のコマンドでデプロイ`SECRET_KEY_BASE=$(cat tmp/development_secret.txt) sls deploy`（devのキーをこのように使い回すのは良くないですが、デモなので楽します）。実行結果が教えてくる生成されたページに行きます\n\nサーバーレス化に共通ですが、主な工数はAPI Gatewayが送りつけてくる生のeventを、Railsアプリが処理できる引数にする変換処理と、`/tmp`以外への書き出しを封じることになります。\n\nRalisはShopifyが作ったbootsnapがデフォで入りましたが、こちらはコールドスタートでキャッシュの作り直しが都度発生するので、パフォーマンスが悪化するケースがあり相性が悪いです。環境変数DISABLE_BOOTSNAP=trueで無効にさせてもらっています。サーバーレス化にトライする今日まで存在さえ知らなかったので勉強になりました。\n\n## 参考\n\n- https://nihemak.hatenablog.com/entry/2019/01/15/015802\n- https://qiita.com/tsutorm/items/d08119b3174c4ff7645d\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumihico%2Fserverless-rails-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fumihico%2Fserverless-rails-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumihico%2Fserverless-rails-demo/lists"}