Error when running a ruby script on AWS Lambda with a gem from a github repository (using Docker)

Viewed 474

I try to build a simple ruby script that checks the balance on the Kraken crypto exchange using the custom jonatack/kraken_ruby_client gem from github which is not available on ruby gems.

AWS Lambda throws the following error:

"errorMessage": "https://github.com/jonatack/kraken_ruby_client.git (at master@cda6c28) is not yet checked out. Run `bundle install` first.",
"errorType": "Init<Bundler::GitError>",
"stackTrace": ["/var/runtime/gems/bundler-2.1.4/lib/bundler/source/git.rb:204:in `rescue in load_spec_files'",
...

What I'm doing:

1. Gemfile

I've added the gem to the Gemfile as usual:

gem 'kraken_ruby_client', git: 'https://github.com/jonatack/kraken_ruby_client.git'

Everything works perfectly on my local machine.

2. Custom Dockerfile

Since the gem requires curb I created a Dockerfile, based on the AWS Lambda image for Ruby 2.7, to install libcurl:

FROM lambci/lambda:build-ruby2.7
RUN yum install -y curl-devel
RUN gem install curb

3. Deployment

I then "deploy" the script:

docker run -v `pwd`:`pwd` -w `pwd` -i -t kraken-app:latest bundle install --deployment
zip build.zip *  -r -x .git/\* \*.sh specs/\* tests/\* \*.zip config/application.yml
aws lambda update-function-code --function-name kraken-app --zip-file fileb://build.zip --region=eu-west-1 --publish --profile XXXX

And it fails with the above error.

What I've tried with multiple StackOverflow answers:

1. Do what the error says - bundle install

I "bundle installed" and "bundled" as much as I could

2. Paths

All gems from Rubygems are installed into vendor/bundle/ruby/2.7.0/gems/, while the gem from github is installed into /vendor/bundle/ruby/2.7.0/bundler/gems/

So I've tried to add the path to $LOADPATH:

load_paths = Dir["./vendor/bundle/ruby/2.7.0/bundler/gems/**/lib"]
$LOAD_PATH.unshift(*load_paths)

As that didn't help, I even manually moved the folder from /bundler/gems to /gems before deploy, but no avail.

3. Local install in Docker image

I amended the Dockerfile to install the gem "locally" in the image by adding:

RUN gem install specific_install
RUN gem specific_install https://github.com/jonatack/kraken_ruby_client.git

I can run the script just fine in Docker in bash:

docker run -it --rm -v "$PWD":/var/task kraken-app:latest bash

Everything works in the Docker container on my local machine but it doesn't work when deployed to Lambda for some reason? Other Lambda functions work perfectly, I just can't get this custom gem to work...

Do you have any idea what else to try?

Thanks in advance!

0 Answers
Related