Quick Start

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! Both Docker and an AWS Account with command line access are required.

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. Otherwise, let's get started.

Steps

  1. New Rails Application
  2. Bootstrap & Setup
  3. First Deploy!
  4. What Just Happened?

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 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 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

For Lamby, these scripts typically build a Docker image. We also do some work to ensure an S3 deployment bucket is created along with setting up Rails encrypted credentials.

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

SAM will build your project into a local .aws-sam directory, zipping it up to S3, and instructing CloudFormation to create your could 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
-------------------------------------------------------------------------------
Outputs
-------------------------------------------------------------------------------
Key           MyAwesomeLambdaHttpApiUrl
Description   Lambda Invoke URL
Value         https://7m473epf5f.execute-api.us-east-1.amazonaws.com/production/

Load the HTTP API URL in your browser and you should see your new Rails app!

MyAwesomeLambda on AWS Lambda with HTTP API

What Just Happened?

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

Lamby 🆕 HTTP API Support     GitHub