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. 🎉
$ 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.
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.
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.
- For an Jets Introduction: Introducing Jets: A Ruby Serverless Framework.
- Also more info at: Jets documentation site.
Jets Links and Tutorial Series
- Introducing Jets: A Ruby Serverless Framework
- Toronto Serverless Presentation: Jets Framework
- Jets Afterburner: Serverless Rails in 5 Minutes
- Mega Mode: Rails on AWS Lambda
- An Introductory CRUD App Part 1
- Deploy to AWS Lambda Part 2
- Debugging Logs Part 3
- Background Jobs Part 4
- IAM Policies Part 5
- Function Properties Part 6
- Extra Environments Part 7
- Different Environments Part 8
- Polymorphic Support Part 9
- Jets Delete Tutorial
- Jets Image Uploads Tutorial with CarrierWave
- Cron Job Tutorial: Backup Route53
- Build an API with the Jets Ruby Serverless Framework