Ruby on Rails on Lambda on Arm64/Graviton2!

metaskills

Ken Collins

Posted on February 18, 2023

Ruby on Rails on Lambda on Arm64/Graviton2!

Today I am happy to announce that Lamby (Simple Rails & AWS Lambda Integration using Rack) now demonstrates just how easy it is to use multi-platform arm64 images on AWS Lambda. If this sounds interesting to you, jump right into our Quick Start guide and deploy a new Rails 7 on Ruby 3.2 Ubuntu image to see it for yourself.

Yay! You're on Rails! welcome page which has been extended by Lamby to show the Rails version, Ruby version, and machine architecture. There is some markup drawing on this page which uses an mechanical arm emoji and a big arrow pointing to the text at the bottom that says aarch64-linux. Cool!

How It Works?

First, AWS has made this incredibly easy since their release in September '21 where AWS SAM can simply switch the deployment architecture in your serverless project's template.yml file:

 Properties:
   Architectures:
-    - arm64
+    - x86_64
Enter fullscreen mode Exit fullscreen mode

Second, make sure your base Docker image supports the arm64 architecture. Most popular images use multi-platform builds already. For example, here is the official Ruby image we use in Lamby's demo project.

$ docker manifest inspect ruby:3.2 | grep arch
            "architecture": "amd64",
            "architecture": "arm64",
Enter fullscreen mode Exit fullscreen mode

Lastly, make sure your deployment machine matches the production target architecture. This is needed to ensure native dependencies (like the MySQL client) are built to match the Docker image architecture eventually being run in production. If you are on a M1/M2 Mac, you can deploy from your own machine.

However, for real production CI/CD, you are better off using something like CircleCI's Arm Execution Environment. Currently GitHub Actions lacks native support for Arm64 Runners, but that issue is being tracked and I suspect is soon to come.

In the meantime, Lamby's demo projects includes a working CircleCI CI/CD example for you that leverages the arm.large machine type.

default-machine: &default-machine
  machine:
    image: ubuntu-2204:current
    docker_layer_caching: true
  resource_class: arm.large
Enter fullscreen mode Exit fullscreen mode

Thanks! Please take the time to learn more about Rails on Lambda using Lamby along with how to use arm64 with Graviton2 with your Lambda applications on our site:

💖 💪 🙅 🚩
metaskills
Ken Collins

Posted on February 18, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related