Cover Image: Man Holding Ice Cream Cone Under Cloud by Rakicevic Nenad
There are a number of tools out there for building "serverless" applications, that is applications in which the configuration of the server is someone else's problem. As the developer, you just write the business logic, the engineers at AWS, Netlify, or Google can worry about all that boring infrastructure stuff.
At least, that is the idea.
Today the most popular tool for building serverless applications is probably the Serverless framework. That's a great tool if you're looking to build your application with JavaScript.
However, it has recently become easier to write serverless applications in other languages too!
I'm particularly interested in building software in Ruby, so I am watching the Jets framework. About 98% of Jets is the work of a friend of mine named Tung Nguyen (he's great).
Tung is an AWS expert with a love of Ruby. He chose to build Jets as an interface for building serverless applications powered by AWS with Ruby. It's pretty cool how much work it is able to do for you.
If you want to know more about Tung, he talked about his career on my podcast 🎙
In this tutorial, I'm going to build the most basic app. Well, not quite "Hello, world!" but something pretty simple.
This tutorial assumes you've got Ruby and Bundler installed.
This is a skin-deep exploration of the automation in Jets, and the finished product won't be anything to write home about, but it will give you an idea of how easily Jets can help you prototype with its Rails-like code generation.
The first step is easy. Install Jets:
gem install jets
Hopefully, you see Successfully installed jets-2.0.4
or something similar in your terminal.
Now, we ask Jets to generate an application for us!
jets new example_app
This should spit out a directory with some boilerplate code.
cd example_app
ls -A
.babelrc .git .rspec README.md config package.json
.env .gitignore Gemfile Rakefile config.ru public
.env.development .jetskeep Gemfile.lock app db spec
.env.test .postcssrc.yml Procfile bin node_modules yarn.lock
We can now ask Jets to generate some code for our application:
jets generate scaffold post title:string
You should see something like this:
INFO: You're missing AWS credentials. Only local services are currently available
invoke active_record
create db/migrate/20190814012442_create_posts.rb
create app/models/post.rb
invoke resource_route
route resources :posts
invoke scaffold_controller
create app/controllers/posts_controller.rb
invoke erb
create app/views/posts
create app/views/posts/index.html.erb
create app/views/posts/edit.html.erb
create app/views/posts/show.html.erb
create app/views/posts/new.html.erb
create app/views/posts/_form.html.erb
invoke helper
create app/helpers/posts_helper.rb
Don't worry too much about the AWS credentials, we won't be deploying this toy app to AWS (though if you care to do the AWS setup, it is entirely possible to deploy this app).
Now, we need to ask Jets to spin up a database for us:
jets db:create db:migrate
This should create a database for you and run the migrations that were generated by our scaffold.
At this point, if we start the server, we should be able to interact with the posts
resource.
jets server
Navigate to localhost:8888/posts
and you should be greeted by the following UI:
By clicking the New Post
link, you should be able to create a new Post
resource.
At this point, you're able to perform basic CRUD actions on that resource:
That's all it takes to build a local Jets application. In a future tutorial, I'll explain how each Ruby file maps to an AWS feature and how to deploy the application to AWS for a truly serverless Ruby application.
In the meantime, check out the project on GitHub and help Tung out with a few PRs. ðŸ¤
Top comments (11)
It's a super simple article.
I wanted to know if this works with Ubuntu. I have been getting an error message that looks like this
zeitwerk requires Ruby version >= 2.4.4. The current ruby version is 2.4.1.111.
I have been trying to update Ruby but it keeps saying this
ruby2.5 is already the newest version (2.5.5-1ubuntu1)
Hmm. That sounds like an issue with rbenv, asdf, or RVM (whichever you use).
I have this error when tryin to use it on windows
The number one thing to look at is Tung's LinkedIn Profile as he is quite creative with media attachments and I've learned a few things from him.
I was bit hoping for a more complete example of Jets. Was wondering if this was backed by DynamoDB or Aurora Serverless if it was using Terraform or possibly CloudFormation to manage these resources.
Maybe if I can connect with Tung I could do a tech talk in Toronto at the Serverless meetup on Ruby on Jets.
The biggest question I would have asked Tung is why didn't he call it Ruby on Rockets.
You can hook it up to Dynamo for sure. Planning to do a more complete article later.
The commands looks similar to RoR's commands. Does Jets aims to follow the same 'convention over configuration' path?
To a degree, Jets is very young and the commands are largely designed to smell like Rails.
Very simple and straightforward...😱😱😱 Amazing. Can't wait for the next article...
Thanks! This is just to get a couple of people interested in the framework. I'll write a much more useful article in the future 😉
I don't get it. Is it like 1 big function? Or jets doing a magic on separation?
The second one. The short version: every public method becomes a function, your routes become gateways, jobs are scheduled with cloudwatch, etc.
If you don't want to wait for me to write more articles, Tung has a ton of content at rubyonjets.com!