{"id":16506334,"url":"https://github.com/logandk/serverless-rack","last_synced_at":"2025-04-09T22:17:17.525Z","repository":{"id":33941720,"uuid":"163276669","full_name":"logandk/serverless-rack","owner":"logandk","description":"Serverless plugin to deploy Ruby Rack applications (Sinatra/Rails/Padrino/Cuba etc.) and bundle gems","archived":false,"fork":false,"pushed_at":"2023-03-16T10:14:08.000Z","size":304,"stargazers_count":68,"open_issues_count":4,"forks_count":14,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-09T22:17:12.572Z","etag":null,"topics":["aws-lambda","cuba","hacktoberfest","padrino","rack","rails","ruby","ruby-on-rails","serverless","serverless-framework","serverless-plugin","sinatra"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/logandk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2018-12-27T09:44:10.000Z","updated_at":"2023-08-15T16:07:53.000Z","dependencies_parsed_at":"2024-06-21T12:52:00.083Z","dependency_job_id":"bfb8630a-7adc-41e4-832a-2e7c359a4193","html_url":"https://github.com/logandk/serverless-rack","commit_stats":{"total_commits":61,"total_committers":12,"mean_commits":5.083333333333333,"dds":"0.42622950819672134","last_synced_commit":"017d9e53a1c2985456f087e618f76ef0ac561f1f"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logandk%2Fserverless-rack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logandk%2Fserverless-rack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logandk%2Fserverless-rack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logandk%2Fserverless-rack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/logandk","download_url":"https://codeload.github.com/logandk/serverless-rack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119287,"owners_count":21050755,"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","cuba","hacktoberfest","padrino","rack","rails","ruby","ruby-on-rails","serverless","serverless-framework","serverless-plugin","sinatra"],"created_at":"2024-10-11T15:19:00.898Z","updated_at":"2025-04-09T22:17:17.508Z","avatar_url":"https://github.com/logandk.png","language":"JavaScript","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://logandk.github.io/serverless-rack/assets/header.svg\"\u003e\n\u003c/p\u003e\n\n[![npm package](https://nodei.co/npm/serverless-rack.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/serverless-rack/)\n\n[![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com)\n[![Build Status](https://travis-ci.org/logandk/serverless-rack.png?branch=master)](https://travis-ci.org/logandk/serverless-rack)\n[![Coverage Status](https://codecov.io/gh/logandk/serverless-rack/branch/master/graph/badge.svg)](https://codecov.io/gh/logandk/serverless-rack)\n[![Dependency Status](https://david-dm.org/logandk/serverless-rack.png)](https://david-dm.org/logandk/serverless-rack)\n[![Dev Dependency Status](https://david-dm.org/logandk/serverless-rack/dev-status.png)](https://david-dm.org/logandk/serverless-rack?type=dev)\n\nA Serverless v1.x plugin to build your deploy Ruby Rack applications using Serverless. Compatible\nRack application frameworks include Sinatra, Cuba and Padrino.\n\n### Features\n\n- Transparently converts API Gateway and ALB requests to and from standard Rack requests\n- Supports anything you'd expect from Rack such as redirects, cookies, file uploads etc.\n- Bundler integration, including dockerized bundling of binary dependencies\n- Convenient `rack serve` command for serving your application locally during development\n- CLI commands for remote execution of Ruby code (`rack exec`), rake tasks ('rack rake') and shell commands (`rack command`)\n\n## Install\n\n```\nsls plugin install -n serverless-rack\n```\n\nThis will automatically add the plugin to `package.json` and the plugins section of `serverless.yml`.\n\n## Sinatra configuration example\n\n```\nproject\n├── api.rb\n├── config.ru\n├── Gemfile\n└── serverless.yml\n```\n\n### api.rb\n\nA regular Sinatra application.\n\n```ruby\nrequire 'sinatra'\n\nget '/cats' do\n  'Cats'\nend\n\nget '/dogs/:id' do\n  'Dog'\nend\n```\n\n### config.ru\n\n```\nrequire './api'\nrun Sinatra::Application\n```\n\n### serverless.yml\n\nAll functions that will use Rack need to have `rack_adapter.handler` set as the Lambda handler and\nuse the default `lambda-proxy` integration for API Gateway. This configuration example treats\nAPI Gateway as a transparent proxy, passing all requests directly to your Sinatra application,\nand letting the application handle errors, 404s etc.\n\n```yaml\nservice: example\n\nprovider:\n  name: aws\n  runtime: ruby2.5\n\nplugins:\n  - serverless-rack\n\nfunctions:\n  api:\n    handler: rack_adapter.handler\n    events:\n      - http: ANY /\n      - http: ANY /{proxy+}\n```\n\n### Gemfile\n\nAdd Sinatra to the application bundle.\n\n```\nsource 'https://rubygems.org'\n\ngem 'sinatra'\n```\n\n## Deployment\n\nSimply run the serverless deploy command as usual:\n\n```\n$ bundle install --path vendor/bundle\n$ sls deploy\nServerless: Packaging Ruby Rack handler...\nServerless: Packaging gem dependencies using docker...\nServerless: Packaging service...\nServerless: Excluding development dependencies...\nServerless: Uploading CloudFormation file to S3...\nServerless: Uploading artifacts...\nServerless: Uploading service .zip file to S3 (1.64 MB)...\nServerless: Validating template...\nServerless: Updating Stack...\nServerless: Checking Stack update progress...\n..............\nServerless: Stack update finished...\n```\n\n## Usage\n\n### Automatic bundling of gems\n\nYou'll need to include any gems that your application uses in the bundle\nthat's deployed to AWS Lambda. This plugin helps you out by doing this automatically,\nas long as you specify your required gems in a [Gemfile](https://bundler.io/gemfile.html):\n\n```\nsource 'https://rubygems.org'\n\ngem 'rake'\ngem 'sinatra'\n```\n\nFor more information, see https://bundler.io/docs.html.\n\n### Dockerized bundling\n\nIf your application depends on any gems that include compiled binaries, these\nmust be compiled for the lambda execution environment. Enabling the `dockerizeBundler` configuration\noption will fetch and build the gems using a docker image that emulates the lambda environment:\n\n```yaml\ncustom:\n  rack:\n    dockerizeBundler: true\n```\n\nThe default docker image that will be used will match the runtime you are using.\nThat is, if you are using the `ruby2.7` runtime, then the docker image will be\n`logandk/serverless-rack-bundler:ruby2.7`. You can override the docker image with the\n`dockerImage` configuration option:\n\n```yaml\ncustom:\n  rack:\n    dockerImage: lambci/lambda:build-ruby2.5\n```\n\n### Bundler configuration\n\nYou can use the automatic bundling functionality of _serverless-rack_ without the Rack request\nhandler itself by including the plugin in your `serverless.yml` configuration, without specifying\n`rack_adapter.handler` as the handler for any of your lambda functions.\nThis will omit the Rack handler from the package, but include any gems specified in the `Gemfile`.\n\nIf you don't want to use automatic gem bundling you can set `custom.rack.enableBundler` to `false`:\n\n```yaml\ncustom:\n  rack:\n    enableBundler: false\n```\n\nIn order to pass additional arguments to `bundler` when installing requirements, the `bundlerArgs`\nconfiguration option is available:\n\n```yaml\ncustom:\n  rack:\n    bundlerArgs: --no-cache\n```\n\nIf your `bundler` executable is not in `$PATH`, set the path explicitly using the `bundlerBin`\nconfiguration option:\n\n```yaml\ncustom:\n  rack:\n    bundlerBin: /path/to/bundler\n```\n\n### Rack configuration file\n\nIf your Rack configuration file (`config.ru`) is not in `./`, set the path explicitly using the `configPath`\nconfiguration option:\n\n```yaml\ncustom:\n  rack:\n    configPath: path/to/config.ru\n```\n\n### Local server\n\nFor convenience, a `sls rack serve` command is provided to run your Rack application\nlocally. This command requires the `rack` gem to be installed, and acts as a simple\nwrapper for `rackup`.\n\nBy default, the server will start on port 5000.\n\n```\n$ sls rack serve\n[2019-01-03 18:13:21] INFO  WEBrick 1.4.2\n[2019-01-03 18:13:21] INFO  ruby 2.5.1 (2018-03-29) [x86_64-linux-gnu]\n[2019-01-03 18:13:21] INFO  WEBrick::HTTPServer#start: pid=25678 port=5000\n```\n\nConfigure the port using the `-p` parameter:\n\n```\n$ sls rack serve -p 8000\n[2019-01-03 18:13:21] INFO  WEBrick 1.4.2\n[2019-01-03 18:13:21] INFO  ruby 2.5.1 (2018-03-29) [x86_64-linux-gnu]\n[2019-01-03 18:13:21] INFO  WEBrick::HTTPServer#start: pid=25678 port=8000\n```\n\nWhen running locally, an environment variable named `IS_OFFLINE` will be set to `True`.\nSo, if you want to know when the application is running locally, check `ENV[\"IS_OFFLINE\"]`.\n\nFor use with the `serverless-offline` plugin, run `sls rack install` prior to `sls offline`.\n\n### Remote command execution\n\nThe `rack exec` command lets you execute ruby code remotely:\n\n```\n$ sls rack exec -c \"puts (1 + Math.sqrt(5)) / 2\"\n1.618033988749895\n\n$ cat count.rb\n3.times do |i|\n  puts i\nend\n\n$ sls rack exec -f count.rb\n0\n1\n2\n```\n\nThe `rack command` command lets you execute shell commands remotely:\n\n```\n$ sls rack command -c \"pwd\"\n/var/task\n\n$ cat script.sh\n#!/bin/bash\necho \"dlrow olleh\" | rev\n\n$ sls rack command -f script.sh\nhello world\n```\n\nThe `rack rake` command lets you execute Rake tasks remotely:\n\n```\n$ sls rack rake -t \"db:rollback STEP=3\"\n```\n\n### Explicit routes\n\nIf you'd like to be explicit about which routes and HTTP methods should pass through to your\napplication, see the following example:\n\n```yaml\nservice: example\n\nprovider:\n  name: aws\n  runtime: ruby2.5\n\nplugins:\n  - serverless-rack\n\nfunctions:\n  api:\n    handler: rack_adapter.handler\n    events:\n      - http:\n          path: cats\n          method: get\n          integration: lambda-proxy\n      - http:\n          path: dogs/{id}\n          method: get\n          integration: lambda-proxy\n```\n\n### Custom domain names\n\nIf you use custom domain names with API Gateway, you might have a base path that is\nat the beginning of your path, such as the stage (`/dev`, `/stage`, `/prod`). In this case, set\nthe `API_GATEWAY_BASE_PATH` environment variable to let `serverless-rack` know.\n\nThe example below uses the [serverless-domain-manager](https://github.com/amplify-education/serverless-domain-manager)\nplugin to handle custom domains in API Gateway:\n\n```yaml\nservice: example\n\nprovider:\n  name: aws\n  runtime: ruby2.5\n  environment:\n    API_GATEWAY_BASE_PATH: ${self:custom.customDomain.basePath}\n\nplugins:\n  - serverless-rack\n  - serverless-domain-manager\n\nfunctions:\n  api:\n    handler: rack_adapter.handler\n    events:\n      - http: ANY /\n      - http: ANY {proxy+}\n\ncustom:\n  customDomain:\n    basePath: ${opt:stage}\n    domainName: mydomain.name.com\n    stage: ${opt:stage}\n    createRoute53Record: true\n```\n\n### File uploads\n\nIn order to accept file uploads from HTML forms, make sure to add `multipart/form-data` to\nthe list of content types with _Binary Support_ in your API Gateway API. The\n[serverless-apigw-binary](https://github.com/maciejtreder/serverless-apigw-binary)\nServerless plugin can be used to automate this process.\n\nKeep in mind that, when building Serverless applications, uploading\n[directly to S3](http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingHTTPPOST.html)\nfrom the browser is usually the preferred approach.\n\n### Raw context and event\n\nThe raw context and event from AWS Lambda are both accessible through the Rack\nrequest. The following example shows how to access them when using Sinatra:\n\n```ruby\nrequire 'sinatra'\n\nget '/' do\n  puts request.env['serverless.event']\n  puts request.env['serverless.context']\nend\n```\n\n### Text MIME types\n\nBy default, all MIME types starting with `text/` and the following whitelist are sent\nthrough API Gateway in plain text. All other MIME types will have their response body\nbase64 encoded (and the `isBase64Encoded` API Gateway flag set) in order to be\ndelivered by API Gateway as binary data (remember to add any binary MIME types that\nyou're using to the _Binary Support_ list in API Gateway).\n\nThis is the default whitelist of plain text MIME types:\n\n- `application/json`\n- `application/javascript`\n- `application/xml`\n- `application/vnd.api+json`\n- `image/svg+xml`\n\nIn order to add additional plain text MIME types to this whitelist, use the\n`textMimeTypes` configuration option:\n\n```yaml\ncustom:\n  rack:\n    textMimeTypes:\n      - application/custom+json\n      - application/vnd.company+json\n```\n\n## Usage without Serverless\n\nThe AWS API Gateway to Rack mapping module is available as a gem.\n\nUse this gem if you need to deploy Ruby functions to handle\nAPI Gateway events directly, without using the Serverless framework.\n\n```\ngem install --install-dir vendor/bundle serverless-rack\n```\n\nInitialize your Rack application and in your Lambda event handler, call\nthe request mapper:\n\n```ruby\nrequire 'serverless_rack'\n\n$app ||= Proc.new do |env|\n  ['200', {'Content-Type' =\u003e 'text/html'}, ['A barebones rack app.']]\nend\n\ndef handler(event:, context:)\n  handle_request(app: $app, event: event, context: context)\nend\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogandk%2Fserverless-rack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flogandk%2Fserverless-rack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogandk%2Fserverless-rack/lists"}