Home ci 38. functions / runtimes: Using the Ruby Runtime with Serverless Functions

38. functions / runtimes: Using the Ruby Runtime with Serverless Functions

Last updated on Aug 05, 2025

Using the Ruby Runtime with Serverless Functions

The Ruby runtime is a powerful option for developers looking to leverage Ruby's flexibility and syntax in their serverless functions on Epycbyte. This guide walks you through setting up, writing, and deploying Ruby-based serverless functions.

Introduction

Choosing the right runtime for your serverless functions is crucial. Ruby offers a dynamic and flexible programming experience, making it ideal for tasks that require complex logic or domain-specific languages. With Epycbyte's Ruby runtime, you can compile Ruby code into efficient serverless functions that handle HTTP requests.

Choosing a Runtime

Epycbyte supports the Ruby runtime as part of its edge computing platform. This runtime is available on all plans and allows you to create serverless functions that define a singular HTTP handler. Your Ruby files must reside in an /api directory at your project's root.

Project Structure

  1. Directory Structure:

    • Create an /api directory at the root of your project.
    • Place your Ruby files (e.g., index.rb) inside this directory.
  2. Ruby File Requirements:

    • Each Ruby file must define a handler that matches the do |request, response| signature.
    • The handler can be implemented as either a Proc or a class inheriting from WEBrick::HTTPServlet::AbstractServlet.

Example Implementation

Here’s an example of how to implement a simple Ruby function:

# api/index.rb
require 'cowsay'

Handler = Proc.new do |request, response|
  name = request.query['name'] || 'World'
  response.status = 200
  response['Content-Type'] = 'text/text; charset=utf-8'
  response.body = Cowsay.say("Hello #{name}!", 'cow')
end

This code defines a handler that responds to HTTP requests. It extracts the name parameter from the query string and uses the cowsay gem to generate a formatted response.

Dependency Management

To manage dependencies, you can use a Gemfile. Here’s how to set it up:

# Gemfile
source "https://rubygems.org"
gem "cowsay", "~> 0.3.0"

This file specifies that the cowsay gem should be included in your project dependencies.

Ruby Versioning

Epycbyte supports multiple Ruby versions:

  • Default: Ruby 3.3.x (new deployments)
  • Legacy: Ruby 2.7.x and 2.5.x are no longer supported as of July 2024

You can specify a Ruby version in your Gemfile using the ruby keyword:

source "https://rubygems.org"
ruby "~> 3.3.x"

If you omit the patch version, Epycbyte will automatically use the latest available version.

Deploying Your Function

  1. Bundle Dependencies:

    • Run bundle install --deployment to install all required dependencies in your project directory.
  2. Deploy the Function:

    • Upload your /api directory to Epycbyte’s serverless platform.
    • The function will be compiled into an efficient executable that handles HTTP requests.

Best Practices

  • Testing: Always test your Ruby functions locally before deploying them.
  • Optimization: Use image optimization tools like imagetools to reduce file sizes.
  • Caching: Enable caching for static assets and frequently accessed resources to improve performance.

Resources

By following this guide, you can leverage the power of Ruby in your serverless functions and take advantage of Epycbyte's edge computing capabilities to deliver fast and efficient applications.