Model-based testing (MBT) has emerged as a powerful strategy for maintaining high standards of quality in an efficient and systematic manner. MBT transforms the development process by allowing teams to derive scenarios from models of the system under test. These...
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.)
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.)
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).
Figure 3: A serverless function can be configured to respond to an event when a file is added to a cloud drive
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.
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.
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.
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.
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 (Click here for details of the example):
$ 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.
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.
Related Posts:
Model-Based Testing with Ranorex DesignWise
Model-based testing (MBT) has emerged as a powerful strategy for maintaining high standards of quality in an efficient and systematic manner. MBT transforms the development process by allowing teams to derive scenarios from models of the system under test. These...
What Is OCR (Optical Character Recognition)?
Optical character recognition technology (OCR), or text recognition, converts text images into a machine-readable format. In an age of growing need for efficient data extraction and analysis processes, OCR has helped organizations revolutionize how they process and...
Support Corner: API Testing and Simple POST Requests
Ranorex Studio is renowned for its robust no-code capabilities, which allow tests to be automated seamlessly across web, mobile, and desktop applications. Beyond its intuitive recording features, Ranorex Studio allows custom code module creation using C# or VB.NET,...