Giter Site home page Giter Site logo

logandk / serverless-rack Goto Github PK

View Code? Open in Web Editor NEW
68.0 5.0 14.0 304 KB

Serverless plugin to deploy Ruby Rack applications (Sinatra/Rails/Padrino/Cuba etc.) and bundle gems

License: MIT License

Ruby 28.30% JavaScript 71.39% Roff 0.31%
serverless serverless-plugin aws-lambda ruby rails sinatra rack serverless-framework padrino cuba

serverless-rack's Introduction

npm package

serverless Build Status Coverage Status Dependency Status Dev Dependency Status

A Serverless v1.x plugin to build your deploy Ruby Rack applications using Serverless. Compatible Rack application frameworks include Sinatra, Cuba and Padrino.

Features

  • Transparently converts API Gateway and ALB requests to and from standard Rack requests
  • Supports anything you'd expect from Rack such as redirects, cookies, file uploads etc.
  • Bundler integration, including dockerized bundling of binary dependencies
  • Convenient rack serve command for serving your application locally during development
  • CLI commands for remote execution of Ruby code (rack exec), rake tasks ('rack rake') and shell commands (rack command)

Install

sls plugin install -n serverless-rack

This will automatically add the plugin to package.json and the plugins section of serverless.yml.

Sinatra configuration example

project
├── api.rb
├── config.ru
├── Gemfile
└── serverless.yml

api.rb

A regular Sinatra application.

require 'sinatra'

get '/cats' do
  'Cats'
end

get '/dogs/:id' do
  'Dog'
end

config.ru

require './api'
run Sinatra::Application

serverless.yml

All functions that will use Rack need to have rack_adapter.handler set as the Lambda handler and use the default lambda-proxy integration for API Gateway. This configuration example treats API Gateway as a transparent proxy, passing all requests directly to your Sinatra application, and letting the application handle errors, 404s etc.

service: example

provider:
  name: aws
  runtime: ruby2.5

plugins:
  - serverless-rack

functions:
  api:
    handler: rack_adapter.handler
    events:
      - http: ANY /
      - http: ANY /{proxy+}

Gemfile

Add Sinatra to the application bundle.

source 'https://rubygems.org'

gem 'sinatra'

Deployment

Simply run the serverless deploy command as usual:

$ bundle install --path vendor/bundle
$ sls deploy
Serverless: Packaging Ruby Rack handler...
Serverless: Packaging gem dependencies using docker...
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (1.64 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
..............
Serverless: Stack update finished...

Usage

Automatic bundling of gems

You'll need to include any gems that your application uses in the bundle that's deployed to AWS Lambda. This plugin helps you out by doing this automatically, as long as you specify your required gems in a Gemfile:

source 'https://rubygems.org'

gem 'rake'
gem 'sinatra'

For more information, see https://bundler.io/docs.html.

Dockerized bundling

If your application depends on any gems that include compiled binaries, these must be compiled for the lambda execution environment. Enabling the dockerizeBundler configuration option will fetch and build the gems using a docker image that emulates the lambda environment:

custom:
  rack:
    dockerizeBundler: true

The default docker image that will be used will match the runtime you are using. That is, if you are using the ruby2.7 runtime, then the docker image will be logandk/serverless-rack-bundler:ruby2.7. You can override the docker image with the dockerImage configuration option:

custom:
  rack:
    dockerImage: lambci/lambda:build-ruby2.5

Bundler configuration

You can use the automatic bundling functionality of serverless-rack without the Rack request handler itself by including the plugin in your serverless.yml configuration, without specifying rack_adapter.handler as the handler for any of your lambda functions. This will omit the Rack handler from the package, but include any gems specified in the Gemfile.

If you don't want to use automatic gem bundling you can set custom.rack.enableBundler to false:

custom:
  rack:
    enableBundler: false

In order to pass additional arguments to bundler when installing requirements, the bundlerArgs configuration option is available:

custom:
  rack:
    bundlerArgs: --no-cache

If your bundler executable is not in $PATH, set the path explicitly using the bundlerBin configuration option:

custom:
  rack:
    bundlerBin: /path/to/bundler

Rack configuration file

If your Rack configuration file (config.ru) is not in ./, set the path explicitly using the configPath configuration option:

custom:
  rack:
    configPath: path/to/config.ru

Local server

For convenience, a sls rack serve command is provided to run your Rack application locally. This command requires the rack gem to be installed, and acts as a simple wrapper for rackup.

By default, the server will start on port 5000.

$ sls rack serve
[2019-01-03 18:13:21] INFO  WEBrick 1.4.2
[2019-01-03 18:13:21] INFO  ruby 2.5.1 (2018-03-29) [x86_64-linux-gnu]
[2019-01-03 18:13:21] INFO  WEBrick::HTTPServer#start: pid=25678 port=5000

Configure the port using the -p parameter:

$ sls rack serve -p 8000
[2019-01-03 18:13:21] INFO  WEBrick 1.4.2
[2019-01-03 18:13:21] INFO  ruby 2.5.1 (2018-03-29) [x86_64-linux-gnu]
[2019-01-03 18:13:21] INFO  WEBrick::HTTPServer#start: pid=25678 port=8000

When running locally, an environment variable named IS_OFFLINE will be set to True. So, if you want to know when the application is running locally, check ENV["IS_OFFLINE"].

For use with the serverless-offline plugin, run sls rack install prior to sls offline.

Remote command execution

The rack exec command lets you execute ruby code remotely:

$ sls rack exec -c "puts (1 + Math.sqrt(5)) / 2"
1.618033988749895

$ cat count.rb
3.times do |i|
  puts i
end

$ sls rack exec -f count.rb
0
1
2

The rack command command lets you execute shell commands remotely:

$ sls rack command -c "pwd"
/var/task

$ cat script.sh
#!/bin/bash
echo "dlrow olleh" | rev

$ sls rack command -f script.sh
hello world

The rack rake command lets you execute Rake tasks remotely:

$ sls rack rake -t "db:rollback STEP=3"

Explicit routes

If you'd like to be explicit about which routes and HTTP methods should pass through to your application, see the following example:

service: example

provider:
  name: aws
  runtime: ruby2.5

plugins:
  - serverless-rack

functions:
  api:
    handler: rack_adapter.handler
    events:
      - http:
          path: cats
          method: get
          integration: lambda-proxy
      - http:
          path: dogs/{id}
          method: get
          integration: lambda-proxy

Custom domain names

If you use custom domain names with API Gateway, you might have a base path that is at the beginning of your path, such as the stage (/dev, /stage, /prod). In this case, set the API_GATEWAY_BASE_PATH environment variable to let serverless-rack know.

The example below uses the serverless-domain-manager plugin to handle custom domains in API Gateway:

service: example

provider:
  name: aws
  runtime: ruby2.5
  environment:
    API_GATEWAY_BASE_PATH: ${self:custom.customDomain.basePath}

plugins:
  - serverless-rack
  - serverless-domain-manager

functions:
  api:
    handler: rack_adapter.handler
    events:
      - http: ANY /
      - http: ANY {proxy+}

custom:
  customDomain:
    basePath: ${opt:stage}
    domainName: mydomain.name.com
    stage: ${opt:stage}
    createRoute53Record: true

File uploads

In order to accept file uploads from HTML forms, make sure to add multipart/form-data to the list of content types with Binary Support in your API Gateway API. The serverless-apigw-binary Serverless plugin can be used to automate this process.

Keep in mind that, when building Serverless applications, uploading directly to S3 from the browser is usually the preferred approach.

Raw context and event

The raw context and event from AWS Lambda are both accessible through the Rack request. The following example shows how to access them when using Sinatra:

require 'sinatra'

get '/' do
  puts request.env['serverless.event']
  puts request.env['serverless.context']
end

Text MIME types

By default, all MIME types starting with text/ and the following whitelist are sent through API Gateway in plain text. All other MIME types will have their response body base64 encoded (and the isBase64Encoded API Gateway flag set) in order to be delivered by API Gateway as binary data (remember to add any binary MIME types that you're using to the Binary Support list in API Gateway).

This is the default whitelist of plain text MIME types:

  • application/json
  • application/javascript
  • application/xml
  • application/vnd.api+json
  • image/svg+xml

In order to add additional plain text MIME types to this whitelist, use the textMimeTypes configuration option:

custom:
  rack:
    textMimeTypes:
      - application/custom+json
      - application/vnd.company+json

Usage without Serverless

The AWS API Gateway to Rack mapping module is available as a gem.

Use this gem if you need to deploy Ruby functions to handle API Gateway events directly, without using the Serverless framework.

gem install --install-dir vendor/bundle serverless-rack

Initialize your Rack application and in your Lambda event handler, call the request mapper:

require 'serverless_rack'

$app ||= Proc.new do |env|
  ['200', {'Content-Type' => 'text/html'}, ['A barebones rack app.']]
end

def handler(event:, context:)
  handle_request(app: $app, event: event, context: context)
end

serverless-rack's People

Contributors

bongole avatar codeluggage avatar dependabot[bot] avatar dnicolson avatar joelvh avatar logandk avatar rickselby avatar shalvah avatar simonrentzke avatar stympy avatar you54f avatar zbristow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

serverless-rack's Issues

cannot load such file -- bundler/setup

Following the example on the readme I get this error:

Init error when loading handler rack_adapter.handler
{
"errorMessage": "cannot load such file -- bundler/setup",
"errorType": "Init<LoadError>",
"stackTrace": [
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/task/rack_adapter.rb:10:in `<top (required)>'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'"
]
}
START RequestId: 056272b6-2f57-41fe-b9b0-5a6a7bb16fb3 Version: $LATEST
Init error when loading handler rack_adapter.handler
{
"errorMessage": "cannot load such file -- bundler/setup",
"errorType": "Init<LoadError>",
"stackTrace": [
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/task/rack_adapter.rb:10:in `<top (required)>'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'"
]
}
END RequestId: 056272b6-2f57-41fe-b9b0-5a6a7bb16fb3
REPORT RequestId: 056272b6-2f57-41fe-b9b0-5a6a7bb16fb3	Duration: 218.89 ms	Billed Duration: 300 ms Memory Size: 1024 MB	Max Memory Used: 20 MB
Unknown application error occurred
Init<LoadError>
START RequestId: b23075d6-fc4f-4196-805a-ff227cc4fc5c Version: $LATEST
Init error when loading handler rack_adapter.handler
{
"errorMessage": "cannot load such file -- bundler/setup",
"errorType": "Init<LoadError>",
"stackTrace": [
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/task/rack_adapter.rb:10:in `<top (required)>'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'"
]
}
END RequestId: b23075d6-fc4f-4196-805a-ff227cc4fc5c
REPORT RequestId: b23075d6-fc4f-4196-805a-ff227cc4fc5c	Duration: 228.12 ms	Billed Duration: 300 ms Memory Size: 1024 MB	Max Memory Used: 20 MB
Unknown application error occurred
Init<LoadError>
Init error when loading handler rack_adapter.handler
{
"errorMessage": "cannot load such file -- bundler/setup",
"errorType": "Init<LoadError>",
"stackTrace": [
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/task/rack_adapter.rb:10:in `<top (required)>'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'"
]
}
START RequestId: 3e2ebcbf-d10e-4579-b2d5-ef7ef02789b2 Version: $LATEST
Init error when loading handler rack_adapter.handler
{
"errorMessage": "cannot load such file -- bundler/setup",
"errorType": "Init<LoadError>",
"stackTrace": [
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/task/rack_adapter.rb:10:in `<top (required)>'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'"
]
}
END RequestId: 3e2ebcbf-d10e-4579-b2d5-ef7ef02789b2
REPORT RequestId: 3e2ebcbf-d10e-4579-b2d5-ef7ef02789b2	Duration: 234.63 ms	Billed Duration: 300 ms Memory Size: 1024 MB	Max Memory Used: 20 MB
Unknown application error occurred
Init<LoadError>

Query parameters are not being parsed

I'm using this as a gem for a Sinatra app running in an AWS lambda. I'm having issues making a request with a query parameter containing a string (e.g. GET /user-record/users?q=ddd%20d). In my local environment (using rack), the params hash contains the query with a space ({"q"=>"ddd d"}), but in AWS, it comes through with the %20 ({"q"=>"ddd%20d"}).

I think this is because Rack::Utils.build_query (called in parse_query_string) is calling Rack::Utils.escape on all the parameters, so they're effectively double escaped.

I think the result of build_query needs to be unescaped for this to function properly?

serverless-offline 6.x compatibility

@logandk I'm having issues upgrading to serverless-offline 6.x. Have you been able to use both of these plugins together?

The error I get indicates that the Ruby artifacts are not present in the root of the project when the offline function is triggered. When I copied the files there manually, I got past this error.

Any ideas?

Thanks!

[offline] Loading handler... (/code/rack_adapter)
Error: Command failed with exit code 1: ruby /code/node_modules/serverless-offline/dist/lambda/handler-runner/ruby-runner/invoke.rb rack_adapter handler
/.rbenv/versions/2.5.6/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- ./rack_adapter (LoadError)
	from /.rbenv/versions/2.5.6/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
	from /code/node_modules/serverless-offline/dist/lambda/handler-runner/ruby-runner/invoke.rb:73:in `<main>'
    at makeError (/code/node_modules/execa/lib/error.js:59:11)
    at handlePromise (/code/node_modules/execa/index.js:114:26)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at RubyRunner.run (/code/node_modules/serverless-offline/dist/lambda/handler-runner/ruby-runner/RubyRunner.js:104:16)
    at LambdaFunction.runHandler (/code/node_modules/serverless-offline/dist/lambda/LambdaFunction.js:318:20)
    at hapiHandler (/code/node_modules/serverless-offline/dist/events/http/HttpServer.js:457:18)
    at module.exports.internals.Manager.execute (/code/node_modules/@hapi/hapi/lib/toolkit.js:45:28)
    at Object.internals.handler (/code/node_modules/@hapi/hapi/lib/handler.js:46:20)
    at exports.execute (/code/node_modules/@hapi/hapi/lib/handler.js:31:20)
    at Request._lifecycle (/code/node_modules/@hapi/hapi/lib/request.js:312:32)
    at Request._execute (/code/node_modules/@hapi/hapi/lib/request.js:221:9) {
  shortMessage: 'Command failed with exit code 1: ruby /code/node_modules/serverless-offline/dist/lambda/handler-runner/ruby-runner/invoke.rb rack_adapter handler',
  command: 'ruby /code/node_modules/serverless-offline/dist/lambda/handler-runner/ruby-runner/invoke.rb rack_adapter handler',
  exitCode: 1,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: "/.rbenv/versions/2.5.6/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- ./rack_adapter (LoadError)\n" +
    "\tfrom /.rbenv/versions/2.5.6/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'\n" +
    "\tfrom /code/node_modules/serverless-offline/dist/lambda/handler-runner/ruby-runner/invoke.rb:73:in `<main>'",
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

How do you pass environment variables to the build container?

Hi logandk,

I need to use a different container other than the default or lambci/lambda:build-ruby2.7 to target the aarch64-Linux architecture. So I'm using public.ecr.aws/sam/build-ruby2.7:latest-arm64.

I also have private gems I need to bring into the bundle. And there are two ways I know how to do that. Either by using a bundle config command or by environment variables, as explained here: https://bundler.io/man/bundle-config.1.html#CREDENTIALS-FOR-GEM-SOURCES

I've tried this, but I don't think the environment variables are being passed to the container.

provider:
  name: aws
  stage: ${opt:stage}
  region: ${opt:region}
  runtime: ruby2.7
  architecture: arm64
  environment:
    BUNDLE_GEMS__LONGEROUS__COM: "claudette:s00pers3krit"

And looking at this, it doesn't look like there is a way to do custom docker args:

serverless-rack/index.js

Lines 42 to 48 in 7364305

this.dockerArgs = [
"bundle",
"install",
"--standalone",
"--path",
"vendor/bundle",
];

Is what I'm trying to do possible via configuration instead of needing to create a custom image?

Thanks,
John

Utilizing without Serverless

When utilizing the gem without the serverless suite i get the following error on execution:

{
  "errorMessage": "undefined method `[]' for nil:NilClass",
  "errorType": "Function<NoMethodError>",
  "stackTrace": [
    "/var/task/vendor/bundle/ruby/2.5.0/gems/serverless-rack-1.0.3/lib/serverless_rack.rb:93:in `build_environ'",
    "/var/task/vendor/bundle/ruby/2.5.0/gems/serverless-rack-1.0.3/lib/serverless_rack.rb:223:in `handle_request'",
    "/var/task/function.rb:9:in `handler'"
  ]
}

This is my lambda.rb

require 'serverless_rack'

$app ||= Proc.new do |env|
  ['200', {'Content-Type' => 'text/html'}, ['A barebones rack app.']]
end

def handler(event:, context:)
  puts 'Hello testing'
  handle_request(app: $app, event: event, context: context)
end

ive installed using

bundle install --without development --path vendor/bundle
7z a lambda.zip *.rb src/ vendor/ *.ru .bundle Gemfile*

i doing something wrong?

configPath not specified when running locally

i'm getting an error trying to use configPath along with sls rack serve:
configuration /home/hlarsen/Source/work/motobot/config.ru not found

it appears getRackHandlerConfiguration() is only run during packing, which i'm guessing is the problem.

`#close` not called on response body

It looks like format_body is not calling close on the response body after iterating over it. I found this when trying to use Rack::CommonLogger with my app and not seeing the expected log entries show up in my CloudWatch logs. It turns out this middleware relies on body.close to be called to emit a log message.

Since this is part of the Rack spec to call close if the body responds to it, can format_body be updated to do this? I was able to get this middleware working after patching locally, so I can submit a PR with a fix if you'd like.

When `dockerizeBundler` is enabled, `bundlerArgs` isn't passed to `bundle install`

Context

I add development gems (e.g. aws-sdk-ec2, rspec) to Gemfile.
I don't want to include these gems, so I want to pass --without option to bundle install.

serverless.yml

service: monitoring

plugins:
  - serverless-rack

custom:
  rack:
    dockerizeBundler: true
    bundlerArgs: --without development test

Gemfile

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem "gitlab"

group :development, :test do
  gem "aws-sdk-cloudwatch"
  gem "aws-sdk-cloudwatchlogs"
  gem "aws-sdk-ec2"
  gem "aws-sdk-kms"
  gem "pry-byebug"
  gem "rspec"
end

Expected

  • Only runtime gem (e.g. gitlab) is included in zip.
  • Development gems (e.g. aws-sdk gems) aren't included in zip.

Actual

Development gems are included in zip. monitoring.zip is very fat 😢

$ cd .serverless/

$ ls -l monitoring.zip
-rw-r--r--  1 sue445  staff  4852659  2 19 10:47 monitoring.zip

$ unzip monitoring.zip -d monitoring

$ ls -l monitoring/vendor/bundle/ruby/2.5.0/gems/
total 0
drwxr-xr-x   3 sue445  staff   96  2 19 10:48 aws-eventstream-1.0.1
drwxr-xr-x   4 sue445  staff  128  2 19 10:48 aws-partitions-1.136.0
drwxr-xr-x   3 sue445  staff   96  2 19 10:48 aws-sdk-cloudwatch-1.13.0

(snip)

What is problem?

When dockerizeBundler is enabled, bundlerArgs isn't passed to bundle install.

  • serverless-rack/index.js

    Lines 247 to 270 in 57d1a53

    if (this.dockerizeBundler) {
    this.serverless.cli.log("Packaging gem dependencies using docker...");
    const res = child_process.spawnSync("docker", [
    "run",
    "--rm",
    "-v",
    `${this.serverless.config.servicePath}:/var/task`,
    "logandk/serverless-rack-bundler:ruby2.5"
    ]);
    if (res.error) {
    if (res.error.code == "ENOENT") {
    return reject(
    "Unable to run Docker. Please make sure that the docker executable exists in $PATH."
    );
    } else {
    return reject(res.error);
    }
    }
    if (res.status != 0) {
    return reject(res.stderr);
    }
    } else {
  • CMD ["/bin/bash", "-c", "bundle install --path vendor/bundle && chown -Rf `stat -c \"%u:%g\" .` .bundle vendor"]

no predefined type for CLI options is deprecated

1 deprecation found: run 'serverless doctor' for more details
❯ sls doctor
Running "serverless" from node_modules
1 deprecation triggered in the last command:

CLI options definitions were upgraded with "type" property (which could be one of "string", "boolean", "multiple").
Below listed plugins do not predefine type for introduced options:
 - ServerlessRack for "port", "host", "command", "file", "task"
Please report this issue in plugin issue tracker.
Starting with next major release, this will be communicated with a thrown error.
More info: https://serverless.com/framework/docs/deprecations/#CLI_OPTIONS_SCHEMA_V3

https://serverless.com/framework/docs/deprecations/#CLI_OPTIONS_SCHEMA_V3

Incompatible with rack 3

Requests aren't passing via serverless-offline due to:

$app ||= Rack::Builder.parse_file($config['config_path'] || 'config.ru').first
#  undefined method `first' for #<Rack:...

which does not work for rack 3 (it returns the app object alright). The .first call needs to be removed.

Interoperability with serverless-offline

Trying to set up a project with serverless-rack and serverless-offline.

I've started only with serverless-rack, however I have authorizer functions defined for the http config, which don't get called when running serverless-rack standalone.

Because of that, I looked into using serverless-offline, which invoke authorizers, and integrates with ruby. The problem is that, whenever I run sls offline start, gem dependencies are installed every single time. This seems to be some issue with the "packaging bundle" step of serverless-offline, which somehow isn't well connected with serverless-rack (?).

But that's not all: if I run sls offline start, which packages gem dependencies for me (so, I shouldn't need to perform bundle install beforehand), running the authorizer function will fail regardless, saying "/usr/local/lib/ruby/3.2.0/bundler/definition.rb:524:inmaterialize': Could not find aws-sdk-kms-1.37.0, aws-xray-sdk-0.11.5, datado..., the typical error which is called when dependencies weren't installed. This seems to be yet another misconfiguration between serverless-rack and serverless-offline, which expect dependencies to be installed in different places (serverless-offline does not run the invoke script with bundle exec`, would that be the issue?).

I've fixed this temporarily by running everything in a docker container and running bundle install (what serverless-rack expects) before running sls offline start(which will reinstall the same set of dependencies someplace else).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.