No infrastructure, just code. Learn the simplicity of serverless

Tags: serverless, cloudnative, programming
Published: 2021-08-26 06:00:52

_*\[guide on how to build and deploy an app using Nimbella Serverless platform]*_

The Nimbella platform unifies the programming experience for the cloud with a serverless foundation. In this way, developers can deliver a complete and integrated solution that is enterprise-ready and multi-cloud ready. Nimbella is designed from the ground up to address the needs of event-based applications, long-running applications, stateful workloads, and more complex use cases including artificial intelligence and machine learning.

## What is serverless?
Serverless is a cloud-native development model that allows developers to build and run applications without having to manage cloud infrastructure like servers.

There are still servers in serverless, but they are abstracted away from app development. A cloud provider handles the routine work of provisioning, maintaining, and scaling the server infrastructure. Developers can simply package their code in containers for deployment.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1zum9ys5nzdwpl90s58.png)

Once deployed, serverless apps respond to demand and automatically scale up and down as needed. Serverless offerings from public cloud providers are usually metered on-demand through an event-driven execution model. As a result, when a serverless function is sitting idle, it doesn’t cost anything.

Nimbella is a serverless cloud that helps developers and organizations adopt a cloud strategy focused on rapidly delivering business value in a changing cloud landscape. Nimbella is backed by proven enterprise-grade open source software and offers organizations the peace of mind of being able to run across multiple clouds, including private infrastructure.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ivh5148ptr2qlo83ecx.png)

## Prerequisites
To complete this tutorial, you will need a Nimbella account. If you don’t have an existing account, visit the [Nimbella Signup page](https://nimbella.com/signup) and create an account for free.

## Steps to build and deploy an app using Nimbella Serverless platform

### Step 1: Downloading the Nimbella CLI
* Let us install the Nimbella CLI by following the instructions provided in the [nimbella documentation](https://docs.nimbella.com/install).
* To verify whether the nimbella CLI is installed or not, let's open a command prompt (or Terminal), and enter the following:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/18sswmetpinnrqbaqb3j.png)

### Step 2: Connecting Nimbella CLI to your account
* Once the CLI is installed we need to link it to our Nimbella account for that reason we can use [auth](https://docs.nimbella.com/nim-cmds/auth) command in the nimbella CLI.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hbcsi6auze27kwlsd84d.png)
* Some of the features provided by auth command are listed below details
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ar6pmy7ugd0nsaj8bsmp.png)
* Now to connect the CLI to our Nimbella account we will be running the following command in the terminal.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/310suvs1rkjhkr27qedm.png)
* The above command will open our default browser for authentication once that is done our account will be connected.
### Step 3: Creating our project
* To create a project we will use the [project](https://docs.nimbella.com/projects#about-projects) command with the following syntax:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4goyevo5babtsj22683l.png)
* Nimbella supports different [languages](https://docs.nimbella.com/runtime#supported-languages), So we can choose anyone from the below list:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4q261tcoi8j7nddr4tr.png)
* Create a project folder with the name **my-first-project** and language as javascript by running the below command in the terminal.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ffjjxrmwt271sbmqj25.png)
* As we can see our project has a fixed directory structure, which determines how projects are deployed. The below diagram summarizes the directory structure of an individual project with no project configuration.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yjjhcgw5rsjb03bpbfm0.png)
* The hello.js is a file pre-filled with hello function (action) written in JavaScript which we will deploy in the next step.

### Step 4: Deploying our project
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7f9zgie1dcwlonvx2xz9.png)
* As we can see, our project is deployed on the nimbella serverless cloud. We can retrieve the URL for any particular web action by using the action get command, as in the following example, which returns the URL for the hello action created before.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7f9zgie1dcwlonvx2xz9.png)
* Now if we navigate to the above URL in our web browser, we can see the following webpage:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mf4vhf4sz18g7x8c4xe7.png)
* We can also use the project deploy command with a list of projects in a single invocation to deploy them all at once (e.g., nim project deploy example1 example2 … ).
* All the actions we have deployed will be stored in our Nimbella Account, we can retrieve that list by using the action list command:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fg8ci386dpz50cayzoin.png)
* Whenever we deploy a project or invoke an action, a unique activation id will be generated which will be linked to that action.
* We can use the activation list command to list the data of all activations which also include Status, Activation ID, Duration of the activations.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a7k7mkp0jpr73fe6u2n6.png)

* Datetime Status Kind Version Activation ID Start Wait Init Duration Entity
* The Activation ID in the above output will help us in retrieving the result, logs, and data of any particular action we deployed, to do that we can use the following commands:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cqovgt0s03bta9mn1meu.png)

### Step 5: Creating an action
* Instead of creating a project we can also simply create an [action](https://docs.nimbella.com/deployer-specification#actions) and deploy it. This action can be directly invoked, updated, and deleted using the Nimbella CLI.
* Let's create an action by following the below steps:
1. Copy the code following into a file and save it as hello_stranger.js
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hfozz4s3fwqw9psminx.png)
2. Now to deploy this action onto our account type the following command in your terminal:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekgcm7r6sw78uck6zy9t.png)
Using the above command the action will be deployed privately, to deploy it in public use the "--web=true" flag along with the command
We have successfully deployed our action using the nimbella CLI.
3. Let's modify our hello_stranger function with the below code to take place as an input parameter:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f86zf1ix77k5923ksp6z.png)
4. Now to update the code on nimbella we will use the following "update" command:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/alp1s69qw43xq4gtkb20.png)
5. To fetch the output of the hello_stranger action, Let's use the invoke-command.
We can also provide the input parameters to the action using the "-p" flag as shown in the following example:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eurpb0tvkz836e9gdjyj.png)
Not only that we can also delete, get data of action using **delete** and **get** commands.

### Step 6: Project watch
* Nimbella also supports incremental deployment of our project, which means whenever we modify and code or file in our project the watch feature will automatically deploy our modified project to the cloud platform
* Let start the watch feature on our project by using the below steps:
1. Enter the following command in your terminal.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/699zuf15bn2cye4rh8e3.png)
2. Let's try to do some small modifications to our code and check the output
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xxrzg4ich5i9vs2g9dsy.png)
* As we can see, only the files which we modified are getting deployed instead of the whole project.
* This feature will be a lot helpful for developers who constantly need to update and deploy their code.

## Summary
Congratulations! We successfully built and deployed serverless functions, projects that can be invoked from the browser or microservices – all just by using CLI.

## References
<https://www.redhat.com/en/topics/cloud-native-apps/what-is-serverless>

**Author:** G. Sai Dheeraj
Dheeraj is currently pursuing his Bachelor of Technology in Computer Science and is a bug bounty hunter. He is working on becoming a cybersecurity expert and spends most of his time reading articles about security and improving his skills in pentesting. In his free time, you will find him testing his skills through competitive programming and writing tech articles.

</br>
*[This blog](https://nimbella.com/blog/no-infrastructure-just-code-learn-the-simplicity-of-serverless) was initially published on [Nimbella](https://nimbella.com/blog). Keep an eye out for this space and follow us on [Twitter](https://twitter.com/nimbella) for the latest updates.*