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.
However, it has recently become easier to write serverless applications in other languages too!
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 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
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
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. 🤠