AWS Amplify Incompatible with Current Version of Ruby

My company’s website is built with Jekyll on AWS Amplify. After I routinely updated my dependencies, AWS failed to build with this error:

[INFO]: Resolving dependencies...
[INFO]: 
[WARNING]: jekyll-feed-0.16.0 requires ruby version >= 2.5.0, which is incompatible with
           the current version, ruby 2.4.6p354
[ERROR]: !!! Build failed
[ERROR]: !!! Non-Zero Exit Code detected

The Fix

By default, AWS Amplify runs builds on Amazon Linux 2 machines. This has the default Ruby version set to 2.4.6, as you can see in the output. My initial Google results pointed towards needing to make a custom Docker image with a later version of Ruby installed. Yikes, that’s a lot of work.

Fortunately, there’s an easier way: specify the ruby version in your Gemfile:

+ ruby '3.0.0'

  source "https://rubygems.org"
  gem "jekyll", "~> 4.2.0"

Looks like to get past the error, I just needed ruby 2.5.0, but my dev environment used ruby 3.0.0. So I went big.

That’s it! Amplify picked up the specific ruby version and built the new dependencies without issue.

AWS Notice: "We changed the build environment ruby version. We detected that your app requires a specific version of ruby and updated the build environment to use the same version."