In this post and video, we’ll cover how to deploy a Rails application to AWS Lambda Serverless in a few minutes. With Jets Afterburner, you don’t have to make any changes to your Rails application to get it on AWS Lambda. 🎉

Commands

$ gem install jets # outside of Gemfile
$ git clone https://github.com/tongueroo/demo-rails
$ cd demo-rails
$ mkdir -p .jets/app
$ vim .jets/app/.env # add your env variables
$ jets deploy
=> Rails app detected: Enabling Jets Afterburner to deploy to AWS Lambda.
...
Deploying CloudFormation stack with jets app!
05:05:11PM UPDATE_IN_PROGRESS AWS::CloudFormation::Stack demo-rails-dev User Initiated
...
05:06:48PM UPDATE_COMPLETE AWS::CloudFormation::Stack demo-rails-dev
Stack success status: UPDATE_COMPLETE
Time took for stack deployment: 1m 36s.
Prewarming application.
API Gateway Endpoint: https://jp65zxlwf8.execute-api.us-west-2.amazonaws.com/dev/
$

That’s it! We have successfully deployed our Rails application to AWS Lambda. Here’s the Live Demo from the tutorial. The full source code of the Rails project is on Github: tongueroo/demo-rails. More info is available at: Jets Rails Support: Afterburner Mode.

Extra Environments

An interesting benefit of running applications on AWS Lambda is that you only get charged for actual requests. So extra environments are likely in the AWS free tier. You could do this:

JETS_ENV_EXTRA=2 jets deploy
JETS_ENV_EXTRA=3 jets deploy
...
JETS_ENV_EXTRA=8 jets deploy

You essentially get unlimited free environments, each of them taking a few minutes to provision.

Other Live Demos

More examples are in the jets-examples repo.

Considerations

Afterburner mode is pretty awesome but is not a panacea for all Rails applications. Each and every Rails application is different and likely makes assumptions that it’s running on a traditional server not serverless. For example, the app might upload files or images to the filesystem. This doesn’t work on AWS Lambda because the app doesn’t have access to a persistent filesystem. The application would have to be reworked to use a distributed store like S3 instead.

Ruby serverless applications might also use native binary gems. Jets uses Lambda Gems to make for a seamless and much easier deploy process. Lambda Gems is currently in beta, and early signups will receive a special offer for their support.

Hope you’ve enjoyed this article. If you find Ruby on Jets interesting, please give it ⭐️ on GitHub. I’d appreciate it. 👍

More info