Ruby: AWS SAM build error with mongoid package
Same as my last post , I’m not a Ruby developer but I had an opportunity to help move some Ruby applications from EC2 to Lambda on AWS. At the time, I had a problem when I built a Ruby application with AWS SAM framework. Let me share why it happened and how I fixed it.
I executed the build command "sam build‘ for the Ruby application but it failed with the following error message.
1Build inside container returned response {"jsonrpc": "2.0", "id": 1, "error": {"code": 400, "message": "RubyBundlerBuilder:CopySource - [Errno 2] No such file or directory: '/tmp/samcli/source/vendor/bundle/ruby/2.7.0/gems/mongo-2.14.0/spec/support/ocsp'"}}
2
3Build Failed
4Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 72694, 'exitReason': 'BuildInsideContainerError', 'exitCode': 1, 'requestId': 'c9a32492-242a-460b-8633-9c2b8c4b7650', 'installationId': 'a15de333-32e0-4651-b78a-c0843ab41c31', 'sessionId': '970cf38b-8715-42bb-b726-c664597c56ab', 'executionEnvironment': 'CLI', 'pyversion': '3.8.7', 'samcliVersion': '1.15.0'}}]}
It was weird for me because all package files were already installed via "bundle install" command. However, the above error said "No such file or directory" and the file is the following.
1'/tmp/samcli/source/vendor/bundle/ruby/2.7.0/gems/mongo-2.14.0/spec/support/ocsp'
In my Gemfile, I specified 'mongoid' and when I executed the "bundle install" command, the ‘mongo’ package was also installed because of the dependency. The automatically installed version was "2.14.0" which is the latest version and I checked the above file path in its GitHub repository.
https://github.com/mongodb/mongo-ruby-driver/blob/master/spec/support/ocsp
And then, I realized that the file is a symbolic link to the following path.
1../../.mod/drivers-evergreen-tools/.evergreen/ocsp
And the .mod directory in the above path and "drivers-evergreen-tools" is a symbolic link to the other repository called drivers-evergreen-tools . That’s why it's become a broken link in the installed source code directory.
So, I checked the commit log in the mongo package repository and the file was added on 9 Sep 2020. And then, I saw the list of the mongo package’s version on the gems site. And it said as follows.
12.14.0 - December 01, 2020 (886KB)
22.14.0.rc1 - October 09, 2020 (883KB)
32.13.2 - December 01, 2020 (862KB)
42.13.1 - October 09, 2020 (855KB)
52.13.0 - July 30, 2020 (855KB)
So first, I deleted the installed directory and modified the version to 2.13.2 in the Gemfile as follows. And then, install the package again via "bundle install" command.
1gem 'mongo', '~> 2.13.2'
Luckily, the broken link had disappeared and succeeded to build by "sam build" command.
So, I’m not sure what’s OCSP exactly and why they put the link in the repository. However, I hope it will be helpful for somebody who has the same problems.