Figure 1: The evolution of deployment units from physical computers to abstracted functions is core to Serverless Computing
Figure 2: In a serverless computing environment, application behavior is defined by functions that are represented by endpoints in an API Gateway
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
Watch our free Ranorex Webtestit and Sauce Labs webinar
Build & Execute Selenium Tests at Scale: View our on-demand live demonstration of how Ranorex Webtesatit is optimized for building UI web tests with Selenium and Protractor.
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
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
Figure 7: Running an Azure Function in debug mode (1) under VS Code using the Azure Functions extension reports function execution time. (2)
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.
$ 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.