Home > Back-end >  Ruby bundle version doesn't match Ruby AWS Lambda function version
Ruby bundle version doesn't match Ruby AWS Lambda function version

Time:05-04

I created a Lambda function on AWS and selected the runtime: Ruby version 2.7.0. Then I deployed my Ruby function with .zip file archives to this AWS Lambda function using following commands:

bundle config set --local path 'vendor/bundle'
bundle install
zip -r my_function.zip lambda_function.rb vendor
aws lambda update-function-code --function-name test-function --zip-file fileb://my_function.zip 

Deploying was successful, however all the libraries are added to vendor/bundle/ruby/2.4.0/..., but not vendor/bundle/ruby/2.7.0/...

  adding: vendor/bundle/ruby/2.4.0/ (stored 0%)
  adding: vendor/bundle/ruby/2.4.0/build_info/ (stored 0%)
  adding: vendor/bundle/ruby/2.4.0/doc/ (stored 0%)
  adding: vendor/bundle/ruby/2.4.0/gems/ (stored 0%)
  adding: vendor/bundle/ruby/2.4.0/gems/aws-eventstream-1.2.0/ (stored 0%)
  adding: vendor/bundle/ruby/2.4.0/gems/aws-eventstream-1.2.0/CHANGELOG.md (deflated 50%)
  adding: vendor/bundle/ruby/2.4.0/gems/aws-eventstream-1.2.0/LICENSE.txt (deflated 65%)
  adding: vendor/bundle/ruby/2.4.0/gems/aws-eventstream-1.2.0/lib/ (stored 0%)
  adding: vendor/bundle/ruby/2.4.0/gems/aws-eventstream-1.2.0/lib/aws-eventstream.rb (deflated 63%)
  adding: vendor/bundle/ruby/2.4.0/gems/aws-eventstream-1.2.0/lib/aws-eventstream/ (stored 0%)
  adding: vendor/bundle/ruby/2.4.0/gems/aws-eventstream-1.2.0/lib/aws-eventstream/types.rb (deflated 62%)
  adding: vendor/bundle/ruby/2.4.0/gems/aws-eventstream-1.2.0/lib/aws-eventstream/header_value.rb (deflated 57%)
  ...

I could not find what causes the problem. How can I deploy the lambda with adding the libraries to vendor/bundle/ruby/2.7.0/...?

The GEMFILE.lock file is:

GEM
  remote: https://rubygems.org/
  specs:
    aws-eventstream (1.2.0)
    aws-partitions (1.547.0)
    aws-sdk-core (3.125.1)
      aws-eventstream (~> 1, >= 1.0.2)
      aws-partitions (~> 1, >= 1.525.0)
      aws-sigv4 (~> 1.1)
      jmespath (~> 1.0)
    aws-sdk-sqs (1.49.0)
      aws-sdk-core (~> 3, >= 3.125.0)
      aws-sigv4 (~> 1.1)
    aws-sigv4 (1.4.0)
      aws-eventstream (~> 1, >= 1.0.2)
    bindata (2.4.10)
    colorize (0.8.1)
    jmespath (1.4.0)
    json (2.6.1)
    redis (4.5.1)

PLATFORMS
  x86_64-darwin-20

DEPENDENCIES
  aws-sdk-sqs
  bindata
  colorize
  json
  redis

BUNDLED WITH
   2.3.4

CodePudding user response:

You're using Ruby 2.4.0 locally to bundle your Ruby application which makes Bundler (correctly) believe that you're targeting 2.4.0, which then results in the vendor/bundle/ruby/2.4.0/ folder being populated.

You should instead install and use Ruby 2.7.0 to sync your local Ruby version to the Lambda runtime you are targeting.

After verifying with ruby -v that you are indeed on 2.7.0, reinstall Bundler (gem install bundler) and then rerun the above commands.

You should then have the vendor/bundle/ruby/2.7.0/ folder populated instead after running bundle install, with the output of zip -r also showing that.

  • Related