I've been having trouble deploying a project to AWS lambda, the code works on my laptop just fine, but deploying on Lambda yields issues related to the google-protobuf gem. It is the only gem in my package that has multiple versions for different architectures, so I believe it is related to this.
I tried installing this gem directly, ie without bundler, but I got an error that the rake failed, with references that it could not find a directory:
/Users/myUser/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/rake-13.1.0-arm64-linux/exe/rake (LoadError)
This leads me to believe that it isn't able to be installed because rbenv only has arm64-darwin directory. How can I install rbenv based in arm64-linux architecture? Or really any other solution would be greatly appreciated.
You didn't provide a copy of your Gemfile or Gemfile.lock, or attach any meaningful logs. As a result, we can only guess what the actual build or runtime are. This answer will not be continuously updated to match an incomplete and non-reproducible question. However, some educated guesses can be made, and I provide some actionable platform-dependent gem management steps for you below.
You say that you're doing something fairly manual rather than using Bundler. It's unclear why you're doing that, as you should either be using Bundler dynamically or vendoring your gems for the target platform ahead of time.
Gems, especially those that use native extensions, require platform-specific builds and (quite likely) dynamic libraries that aren't available on your target host. You should add all target platforms to your Gemfile.lock with bundle-lock so that bundle install
will resolve gems properly when run on the target. You can do that with something like:
bundle lock --add-platform arm64-linux
This will ensure that arm64-linux
is added to the list of platforms that your Gemfile.lock will correctly manage. Running bundle platform
in the directory with your Gemfile.lock will then provide you something similar to the following:
Your platform is: arm64-darwin-23
Your app has gems that work on these platforms:
* arm64-darwin-23
* arm64-linux
* ruby
If you need a more specific platform, you may need to run gem environment platform
on the remote host to see what it thinks the specific platform is, and add that one instead.
If you are missing dependencies, then you may need to take a closer look at the remote container. For example, it might be basd on musl libc instead of glibc, or particular build dependencies may be missing. If so, you'll need to debug the build process or review the documentation to determine what build dependencies may be missing on your target platform.
You may also consider testing the specific AWS image used for your Lambda containers locally by following the instructions in that section of the documentation, or in others more appropriate to whatever image you're using. In any case, testing locally will save you a lot of time and trouble with round-tripping so you can isolate the problem faster.
There are probably other things you can do as well, but this is generally the right place to start. It should at least get you pointed in the right direction.