Corticon.js Deployment on Microsoft Azure Functions
Deploy Progress Corticon.js Decision Services on Azure Functions to accelerate deployment and simplify operations at scale of your application’s business rules.
This tutorial will demonstrate deploying a rental car decision service generated by Corticon.js on Azure Functions. To prepare for the tutorial, the only Azure web portal interaction that is necessary, is signing up for Azure. The guide is currently Windows based and assumes an existing Azure account. You may choose to forgo the shell-instructions and retrace the steps outlined here in the Azure web console. Essentially you will have to follow this guide
, placing the contents of everything under the CarsDecisionService directory in the deployment.zip file. You may also use Visual Studio Code with the Azure extension and follow this guide
. NB: MS Visual Studio only supports deploying .NET/C# based projects.
The decision service we will be deploying in this tutorial is based on a typical rental car damage waiver insurance scenario. The end-result will be a fully functional web service, that is publicly available on the internet and can be integrated into any frontend application. As input this service expects driver information such as age, gender, driving experience and the desired collision damage waiver plan (‘Full’ or ‘Limited’). It will then output a calculated insurance premium based on the driver details provided. Rental car insurances usually rely on accident statistics for calculating the premiums. Therefore, younger drivers identifying as male typically face much higher premiums than non-male and/or older drivers (gender is not a binary spectrum).
CarsDecisionService - The project/app container which can hold various functions. Its configuration is largely auto generated using CLI tools.
CarsDecisionService/RentalInsurance - The node HTTP endpoint which makes the CorticonJS DS available for calling. This is an actual Azure Functions function.
Createapp.bat - A Windows Batch Script that runs the necessary Azure CLI Commands to create the Azure Functions Deployment environment in the cloud.
testCarsPayload.json - A sample JSON that can be used as a request body to verify the DS is working correctly - (look for a “status: success” in the response)
System Prerequisites/ Tested With
(Optional) A good shell that also comes with git couldn't hurt (e.g. cmder)
Setup project & verify local run
choco install curl
(Optional) Install curl to ultimately test the HTTP endpoint or use a HTTP Client of choice (Insomnia, Postman etc)
choco install nodejs-lts
(Optional) Install latest LTS node, if not installed:
npm i -g azure-functions-core-tools@3 --unsafe-perm true
Install Azure Functions Core Tools CLI globally (ie accessible from any project)
git clone https://github.com/corticon/corticon.js-samples.git
Then clone this repo into a work directory of your choice (If you want to use the CLI tools to create your own Functions-project, jump to the bottom)
- In directory corticon.js-samples\Azure\CarsDecisionService install the Cars Corticon DS bundle from GitHub by executing
And finally run the Function in a local Azure environment
You should see output similar to this, which means your service is available locally: <br bcx0"="">RentalInsurance: [GET,POST]
You can verify that it’s running correctly by POSTing the the HTTP endpoint:
corticon.js-samples\Azure\curl --request POST --url
http://localhost:7071/api/RentalInsurance --header "content-type:
application/json" --data @testCarsPayload.json
Finished! You should have a Corticon decision service running in a node HTTP service shell running in a locally emulated Azure environment.
Deploying to Azure Functions
This is the main reason why you clicked on this tutorial. If you haven't signed up for Azure yet, please do so now
choco install azure-cli
Install the Azure CLI (az) globally from anywhere in your file system
Once installed, log into Azure. This should open a web login:
Then cd to corticon.js-samples\Azure and run
This sets up a few Azure cloud services: a resource group, a storage account and an app service/function container (+ app insights and service plan automagically). For detailed settings like deployment regions check the batch file. NB: on a trial plan, any other region than “eastus”results in subsequent errors, either when creating the storage engine or the function container.
func azure functionapp publish CarsDecisionService
Now that all the admin is out of the way you can finally deploy your Corticon DS to Azure; in corticon.js-samples\Azure\CarsDecisionService please execute
Functions in CarsDecisionService:
RentalInsurance - [httpTrigger]
This publishing step may occasionally time out, but will ultimately deploy the project. If successful, you should see something along these lines:
corticon.js-samples\Azure\curl --request POST --
url https://carsdecisionservice.azurewebsites.net/api/rentalinsurance?code=DASDDASDASDASDASDASDAS123123123123123== --header "content-type:
application/json" --data @testCarsPayload.json
The code-token is important! You can and should verify that everything is setup correctly by modifying the URL in the curl statement from above to:
Your cloud call should not only return a 200 OK, but also echo a slightly modified JSON, returning an insurance premium rate and adding a "status": "success" in the JSON.
You have successfully deployed a Corticon.js Decision Service in the (Microsoft) serverless cloud.
Create your own Service
func new --template "Http Trigger" --language "node" --name
To actually create a function endpoint/handler within that container, you could run for instance
This would create code for an HTTP endpoint responding to GET and POST. There are other languages and templates available.
npm install –save rental-insurance@git+https://github.com/steinerj/node-cars-decision-serv ice.git
In our sample, Corticon.js DS bundle is added as an npm dependency on the container level, therefore, it would be available to all functions in that container. It is also perfectly viable to just add it on a function level or add the bundle to the project as a hard dependency. If npm sounds good, you can add a dependency to the containers package.json by:
Now you have successfully utilized Corticon.js Azure functions!