As I mentioned in the post about the demonstration of the creation and development of the code of an azure function here is the time to publish it in our subscription Azure.
But before that, we will have to create all the resources that will be used for the proper functioning of the DMP calculation function.
In this post, I decided to perform all the online actions with the Azure CLI. In another post, I will present the solution with Azure Resources Manager (ARM) for automated deployment.
Before we begin here is what we need:
So, when we have all our “ingredients” we will be able to start the “recipe”. Let’s go!!
I voluntarily used Visual Code to retrieve the sources. To test and validate that my function compiles well, works properly and then be able to publish it on Azure.
To do this, simply review the demo ticket on azures functions. In short:
If all goes well the command gives you the url to call to test your function, like this:
in response the following message must be provided:
Azure Function for calculated PGCD(120,8) is 8
So, we know that our function is ready to go online. But first, we need to prepare our resources on Azure.
To deploy and execute our Azure function, we need multiple resources. In the interest of simplicity of understanding I stopped to provide the prerequisites in the orders and I did not go into more details. The aim is to publish a function and make it available.
Here is the list of resources:
All resources must belong to a group of resources. It is a functional container with a set of metadata. Moreover, they can only belong to one group of resources at a time.
We will therefore place the following order:
az group create --name functionapp-rg --location francecentral
to check the status of our group resource we can place the following command:
az group list --output table
who will return to us (for my part I had no group of resources before):
Name Location Status -------------- ------------- --------- functionapp-rg francecentral Succeeded
az group show --name functionapp-rg -otable
Now we need a storage account. To make it simple a storage account will allow us to store all types of information in Azure in a single domain name and accessible via HTTP/S. The data is durable, secure and highly available.
For this we will place the following command to make its creation and assign it to our group resource created previously.
az storage account create --name funcaccount --resource-group functionapp-rg
After a more or less long delay, an object in JSON format will appear.
The information on the storage account(s) can be obtained with the following command:
az storage account list -o table
To have the information on our account only the following order:
az storage account show --name funcaccount
Its purpose is to provide functions within it with an execution context and behavior defined by the Function App. It is important to remember that all functions in a Function App must have the same development language.
The scability is at the Function App level which means that scaling is done on all functions in the application. They therefore share all the resources per function instance.
The Deployment is done on all the functions of the application.
We will now create our Function App with the following command:
az functionapp create --name pgcdfuncapp --resource-group functionapp-rg --storage-account funcaccount --consumption-plan-location francecentral --functions-version 3
This is the name of our new FunctionApp.
This is the name of the resource group where we want to implement our function application.
This is the storage account we created just before.
This is the geographical location where our function application will be hosted. If you want to have a list of available locations, simply place the following command:
az functionapp list-consumption-locations -o table
This is the runtime version for Azures Functions, currently there is version 1.x 2.x 3.x. By default, the version is 2.x, so here we will use version 3.x.
Now that we have created our infrastructure in Azure to host our function. We will deploy it. To do this, using our terminal session we will go to the directory that contains the project file of our function. Then we will use the following command:
func azure functionapp publish pgcdfuncapp
If the deployment has been successfully completed. the command report will give you a semblance of the following message:
Deployment completed successfully. Syncing triggers... Functions in pgcdfuncapp: pgcddemo - [httpTrigger] Invoke url: https://pgcdfuncapp.azurewebsites.net/api/pgcd?code=goc4uOYiqbXR4mVi6XhFL3/Y8sPr0G1K9Sh0h62uZK3avVsVgZePEg==
To test I will use the following curl command:
The result will be:
Azure Function for calculated PGCD(123,78) is 3
Sont les paramètres propres à la fonction de calcul du PGCD.
C'est le jeton de sécurité qui permet à l'appelant d'accéder et d'exécuter la fonction. D'autres moyen au niveau sécurité sont disponibles car plus sécuritaire.
Are the parameters specific to the DMP calculation function.
It is the security token that allows the caller to access and execute the function. Other means at the security level are available because they are safer.
As it was only for a demonstration we will clean up the resources allocated on our subscription to avoid any unnecessary expenses. To do this, just delete our group of resources and Azure will take charge of destroying taking into account any dependencies all the resources contained. Knowing that if a resource has a lock, it will not be destroyed. To do so, simply perform the following command:Comme ce n’était que pour une démonstration nous allons nettoyer les ressources allouées sur notre souscription pour éviter d’éventuelles dépenses inutiles. Pour cela, il suffit de supprimer notre groupe de ressources et Azure va se charger de détruire en tenant compte des éventuelles dépendances l’ensemble des ressources contenues. En sachant que si une ressource a un verrou elle ne sera pas détruite. Pour cela, il suffit juste d’effectuer la commande suivante :
az group delete --name functionapp-rg
Now you are able to: