Hi folks! I want to share with you one of the most emerging technologies for Cloud Computing. I'm talking about "Functions as a Service" or FaaS. In this article I want you to explore with me an introductory solution. We will build a serverless application, step by step, using the faastRuby platform, and we will make the solution available in the cloud.
faastRuby is an incredible platform and allows us to work easily with serverless functions. The platform is intuitive and very similar to Heroku, where the server infrastructure is totally abstracted.
Click here https://www.faastruby.io to know more about faastRuby.
The faastRuby platform was updated and there were improvements after version 0.5, so I decided to rewrite the Hello World tutorial.
faastRuby is a Serverless Software Development Platform for Ruby and Crystal, made of two main components.
- faastRuby Cloud - where you deploy your applications and functions to.
- faastRuby Local - an SDK that allows you to develop and test rich web applications and APIs in your machine and deploy your app as a set of distributed functions to the platform. Basically all you have to do is write code. No Ops required.
- Account - To get started with the faastRuby Cloud Platform, you'll have to create an account, which you'll use to login on the Platform. A faastRuby account belongs to a person or a company.
- Function - faastRuby apps are built with pure Ruby or Crystal functions. Functions are the unit of deployment of faastRuby apps. Each function is its own thing - they are independent from each other.
- Project - Project is where your application stays. Your project will have a main folder, subfolders, static files and functions.
- Workspace - Workspaces are isolated environments where you deploy your functions to. They are represented by a URL like https://projectName-environment-abs123.tor1.faast.cloud.
- projectName: Your faastRuby project's name.
- environment: Stage is the default environment. You can choose another one like prod, dev, etc.
- abs123: This's the project identifier, used to ensure your workspaces will have unique names. It shouldn't be changed.
Using the faastRuby resources, we're going to create two Ruby functions locally, test them, and deployed them to the cloud.
- ruby 2.6.0
- gem faastruby
Create your own folder for faastRuby projects and enter into it. This is not mandatory. I prefer to use this kind of folder organization, this way, all projects made in faastRuby stay inside this folder.
$ mkdir faastruby $ cd faastruby
Perform this step only if you use the Ruby version manager, RVM:
$ faastruby/> rvm use ruby-2.6.0@faastruby --ruby-version --create
If you do not have the gem installed, perform:
$ faastruby/> gem install faastruby
If you already have faastruby gem installed, just upgrade it:
$ faastruby/> faastruby update
To know if it worked, let's see the gem version. For me this is the current version: 0.5.23. Note that your version may be newer, as the platform is constantly being updated.
$ faastruby/> faastruby -v 0.5.23
$ faastruby/> faastruby signup Welcome to FaaStRuby! Please enter your email address: Email: <<< firstname.lastname@example.org >>>
After entering your email, you can enter with your password.
Now type in a password. It must contain 8 to 50 characters and have at least one uppercase letter, one lowercase letter, one number and one special character @ $ ! % * ? & ************ ✔ Creating your account...
You'll then receive an email with a token for verification. Copy and paste the token into the field indicated below.
You should have received an email with a confirmation token. If you didn't receive an email: - Make sure you sign up with the correct email address - The system won't send an email if you account status is already 'confirmed' Confirmation Token: <<< your token here >>>
Finally, you'll be registered and logged into the platform.
✔ Confirming your account... Login successful!
When you need to login, use the following command:
$ faastruby/> faastruby login Email: email@example.com Password: *********** Login successful.
And when you need to logout, you can use:
$ faastruby/> faastruby logout ## use --all to logout from all machines Logout successful.