Quick Start

A new Rails application deployed to AWS Lambda Containers in a few minutes!

Lamby can be used with existing or new Rails/Rack applications. The quickest way to deploy a new application on AWS Lambda is to use our cookiecutter project template. A few console commands will have you up and running in a few minutes! Before you get started, make sure you have both Docker installed & an AWS Account with command line access setup.

If these tools or AWS Lambda are completely new to you, consider learning how to install Docker, setup an AWS Account, and how Ruby & Lambda work by using this excellent Ruby AWS Lambda Microservice Workshop links above. Otherwise, let's get started.


New Rails Application

The AWS SAM CLI allows you to initialize a new project from a GitHub repository template, commonly called a cookiecutter. Assuming you want to use the full Docker solution that avoids needing to install SAM locally, use this command.

$ docker run \
  --rm \
  --interactive \
  --volume "${PWD}:/var/task:delegated" \
  lambci/lambda:build-ruby2.7 \
  sam init --location "gh:customink/lamby-cookiecutter"

If you have the SAM CLI installed on your system, use can use this command.

$ sam init --location "gh:customink/lamby-cookiecutter"

Bootstrap & Setup

The cookiecutter install would have prompted you for your new application name. This guide will assume the name of my_awesome_lambda was used. All commands below assume you have changed to that directory

$ cd my_awesome_lambda

Lamby's cookiecutter project encourages the use of a normalized script pattern when working with projects. These two commands will bootstrap and setup your system. Typically bootstrap is a one time process where as setup is often run when dependencies change.

$ ./bin/bootstrap
$ ./bin/setup

These scripts typically build a Docker development image and bundle gems. We also do some work to ensure an both an S3 deployment bucket is created along with an ECR Repository for your deployed container image.

First Deploy!

Now your Rails app is ready to be deployed to AWS Lambda via SAM. We make this easy by using a script which builds, packages, and deploys your Rails application.

$ ./bin/deploy

This will run a Lamby build script that duplicates your current project directory into a local .lamby directory and runs typical deployment commands. From there AWS SAM's build command runs which which builds your container image, and instructs CloudFormation to create all your cloud resources as defined in your template.yaml file. During the end of this process, you will see SAM output similar to what is shown below.

CloudFormation outputs from deployed stack
Key           MyAwesomeLambdaHttpApiUrl
Description   Lambda Invoke URL
Value         https://7m473epf5f.execute-api.us-east-1.amazonaws.com/production/

This is an API Gateway HTTP API endpoint which invokes your Rails application using Rack. Load it up in your browser and you should see the familiar welcome to Rails screen. 🎉🎉🎉

Yay! You're on Rails with AWS Lambda Containers

What Just Happened?

You just deployed a new Rails v6 application to AWS Lambda Containers using an AWS Ruby 2.7 base image. This project has everything you need for a server-side API and/or a client JavaScript application. Please take some time to explore your Rails app and how Lamby works in the next section.