Serverless functions and the serverless computing environment
Serverless computing is a game changer. Before serverless computing came along, the deployment unit for an application was a physical computer, a virtual machine or a container. In the serverless computing paradigm the function is the deployment unit. It’s a fundamentally different way of doing business. All computing resources, such as CPU, storage, network and memory have been virtualized away. All that remains is the function. (See Figure 1.)
The evolution from Server to Serverless Computing
Figure 1: The evolution of deployment units from physical computers to abstracted functions is core to Serverless Computing
The role of the developer in the serverless computing paradigm is to create sets of cloud-based functions that are accessed by way of an API. The API is realized as endpoints within an API Gateway scheme. (Figure 2.)
The serverless computing environment
Figure 2: In a serverless computing environment, application behavior is defined by functions that are represented by endpoints in an API Gateway
Once the serverless functions are defined and bound to an API by way of an API Gateway, they are accessed by clients on the internet. The client can be a web page, a mobile app, an IoT device or another service on the web.

Also, a serverless function can be configured to respond to a system event, for example when a file is added to a cloud storage technology such as AWS S3 or Google Cloud Storage (see Figure 3), or when receiving a message from a message queue (see Figure 4).

Serverless Function responding to an event
Figure 3: A serverless function can be configured to respond to an event when a file is added to a cloud drive
Serverless Function responding to messages
Figure 4: A serverless function can be configured to subscribe to messages on a message queue
Serverless functions are compelling in that all the overhead of computing — memory, CPU, storage, and networking — is delegated to the cloud provider. The essential development work, creating the application logic, is left to the developer. And, as stated before, this logic is deployed as a set of cloud-based functions.

Most of the major cloud providers have serverless function products. AWS has Lambda. Google has Cloud Functions. Microsoft has Azure Functions. IBM has IBM Cloud Functions. Red Hat has OpenShift Cloud Functions. At the operational level, each works a bit differently in terms of implementation, but conceptually they are very similar.

Watch our on-demand webinar

Get to Know Ranorex Webtestit: Learn how to build robust and reliable Selenium test suites from installation through to execution with Ranorex Webtestit

Creating serverless functions cloud using a cloud console

As mentioned above, all the major cloud providers offer serverless functions. Serverless functions can be created manually using the console of a particular cloud provider. Figure 5 shows the online Amazon Web Services (AWS) console that is used to create a Lambda serverless function.

Serverless Function in AWS Lambda execution time and test results
Figure 5: After you click the Test button (1) to exercise a serverless function in AWS Lambda, execution time (2) is reported in the test results
The AWS Lambda has a feature that allows you to run and test serverless functions directly in the console.

Figure 6, below, shows the console for creating Google Cloud Functions. This console is similar to the one in AWS Lambda in that you write code directly into and test with the console.

Serverless Function in Google Cloud execution time and test reults
Figure 6: After you click the Testing button (1) to exercise a serverless function in Google Cloud Functions, execution time (2) is reported in the test results
Microsoft provides the capability to create a serverless function directly in the Azure portal. In addition, developers can create Azure Functions using Visual Studio or VS Code. Figure 7 shows an Azure Function being developed in VS Code using JavaScript under Node.js as the programming environment.
Serverless Function debugging in Azure
Figure 7: Running an Azure Function in debug mode (1) under VS Code using the Azure Functions extension reports function execution time. (2)
VS Code has an installable Azure extension that provides the capability to emulate the context and request that is passed to the serverless function. This means that Azure Functions can be debugged directly in VS Code.

A context object describes the run-time environment in which the serverless function is running. The request describes the HTTP request that is passed to the function. Context and request are not special to Azure Functions. All the serverless function technologies use context objects at a conceptual level.

Working with serverless functions at the command line

In addition to using a web-based console to create a serverless function, you can create one using the cloud provider’s SDK. As with consoles, all the major cloud providers publish an SDK that allows developers to create code in a local environment and then publish and test the serverless function in the cloud using the command line.

The following example from AWS shows you how to send a Lambda stored in a zip drive on a local system to the cloud using only the command line:

$ aws lambda create-function \
--region region \
--function-name helloworld \
--zip-file fileb://file-path/helloworld.zip \
--role role-arn \
--handler helloworld.handler \
--runtime nodejs6.10 \
--profile adminuser

Below shows the single command required to publish a Google Cloud Function from Node.js code stored in a local directory to Google Cloud using the Google Cloud SDK (For details of the example click here.):

$ gcloud functions deploy helloGET --runtime nodejs6 --trigger-http

The Azure CLI SDK makes it possible to publish Azure Functions from the command line too, with a process that is similar to the AWS and Google Cloud:

$ az functionapp create --name <app_name> --storage-account <storage_name> --resource-group myResourceGroup \
--plan myAppServicePlan --deployment-source-url https://github.com/Azure-Samples/functions-quickstart-linux

Command line creation of an Azure Function requires a bit of upfront configuration to make a deployment. You can read the details of the process at this link.

Being able to work at the command line is useful in terms of deployment efficiency. However, the real impact is that command line manipulation of serverless functions opens a door that allows the technology to be used in a Continuous Integration/Continuous Deployment CI/CD process. Controlling serverless function technology under CI/CD allows it to be used under automation at web scale.

Putting it all together

Serverless computing provides many benefits to the software development process. Eliminating the extraneous overhead that goes with the software development process will allow developers to focus on what they do best: create behavior. Isolating the deployment unit to the function means that more software can be written faster and tested at a finer grain. However, as with any new technology, there is a learning curve. Also, companies will need to adjust their source control, testing and release processes to accommodate the “functions only” approach to software development. But, after an initial adoption phase, the benefits that serverless computing provide will make it worth the investment of time and money required.

To explore the features of Ranorex Studio risk-free download a free 30-day trial today, no credit card required.

About the Author

Bob Reselman is a nationally-known software developer, system architect, and technical writer/journalist. Bob has written four books on computer programming and dozens of articles about topics related to software development technologies and techniques, as well as the culture of software development. Bob lives in Los Angeles. In addition to his work in a variety of aspects of software development and DevOps, Bob is working on a book about the impact of automation on human employment.

You might also like these articles