Serverless deployment of an Azure Functions App

 

Host web application via Microsoft Azure, Part 3 Serverless Deployment of an Azure Functions App

With the help of Azure Web Apps and Azure Functions, we want to provide a highly available web application for calculating thumbnails without an explicit own infrastructure. In this article of our four-part workshop we take care of the serverless part of the application.

Companies on the topic

Running Functions app without individual code.Running Functions app without individual code.

(Image: Drilling / Microsoft)

In this post, we take care that a serverless Azure Functions App provides the Code for the actual conversion of images. For the logic of the process, i.e. the interaction with the incidentally services, such as the containers created in the second part of this image resizer series, we rely on EventGrid.

Resource providers that have not yet been used must first be registered with the Azure Resource Manager, apart from standard resource providers such asResource providers that have not yet been used must first be registered with the Azure Resource Manager, apart from standard resource providers such as “Compute” or “Storage” in the case of EventGrid.

(Image: Drilling / Microsoft)

This service will trigger our Azure Functions app as soon as a new upload occurs in the image container. For this purpose, it is now also necessary to register the resource provider for EventGrid before connecting EventGrid – if this has not yet happened. This can optionally be done in the cloud shell with …

az provider register --namespace Microsoft.EventGrid

… or in the Azure portal after selecting the currently used Azure Subscription in the menu ” Settings / Resource provider “with a click on” Register “at the provider entry” Microsoft.EventGrid”.

The backend systems get their own storage location for security reasons.The backend systems get their own storage location for security reasons.

(Image: Drilling / Microsoft)

Now we need another Storage Account for our Azure-Functions-resource. How to create a storage account under Azure, we have shown in part 1 of this series. We use the same Account type “StorageV2”, and the same redundancy model (LRS). Nevertheless, it makes sense to separate the storage location of the application data from that of the backend logic. However, since both storage accounts belong to the same team project, they naturally come into the same resource group.

Azure Functions App

Picture: Functions-App-gui1.PNG

You can also create an Azure Functions app via Azure Portal or Cloud Shell.You can also create an Azure Functions app via Azure Portal or Cloud Shell.

(Image: Drilling / Microsoft)

Now we can turn to creating the serverless function, an “Azure Functions App”. We use these for serverless hosting of our resizer function. The creation can again be done either via CLI in the Cloud Shell or in the Azure Portal. The name of the function app used as the default DNS domain for the function app, the name must be unique from Part 2 in Azure, just like with our web app. A function similar to that of web apps the “App Service Plan” fulfils the so-called “Consumption Plan” of Functions Apps.

For serverless hosting of an Azure Functions app, we use the planning type "Consumption (Serverless).“For serverless hosting of an Azure Functions app, we use the planning type ” Consumption (Serverless).“

(Image: Drilling / Microsoft)

To specify this, select the entry “Consumption (serverless)” in step 2 of the Functions app Deployment Wizard at “Plan Type”. In this case, Microsoft Azure im takes care of dynamic scaling and demand-driven execution of the plan. The alternative option “Premium” offers advanced features and better control of dynamic scaling.

In Azure, however, it is also possible with a Functions app on request to select a plan for a classic demand-driven execution with the entry “App Service Plan”, as we have already seen in part 2 with the Web app. However, we remain with serverlos, the usual deployment and billing plan for “function – as-code”.

Of course, we can also deploy our Azure Functions via cloud Shell. We use the Azure CLI again:

az functionapp create --name resizer-function --storage-account azditresizesa --resource-group azditresizerrg --consumption-plan-location eastus --functions-version 2

Configure Functions App

Our Functions app requires credentials to the storage account with the blob storage for source images and thumbnails.Our Functions app requires credentials to the storage account with the blob storage for source images and thumbnails.

(Image: Drilling / Microsoft)

The function requires credentials for the Blob storage account. These can be added to the application settings of the Functions app, for example, with the following two commands:

storageConnectionString=$(az storage account show-connection-string --resource-group azditresizerrg --name azditresizersa1 --query connectionString --output tsv)
az functionapp config appsettings set --name Resizer-Function --resource-group azditresizerrg --settings AzureWebJobsStorage=$storageConnectionString THUMBNAIL_CONTAINER_NAME=thumbnails THUMBNAIL_WIDTH=100 FUNCTIONS_EXTENSION_VERSION=~2

Alternatively, as with the Web app, the login information can also be added in the GUI in the “Configuration” section of “Application settings” in the second part. To do this, click on the edit icon in “AzureWebJobsStorage” and add one of the two connection strings of the storage account that we created in the first part as the basis for the thumbnail container in “Value”.

The Functions app requires additional application settings.The Functions app requires additional application settings.

(Image: Drilling / Microsoft)

This also applies to two other required application settings, “THUMBNAIL_CONTAINER_NAME” and “THUMBNAIL_WIDTH”, which are already included in the above command. Here you must not forget to click on “Save”.

A Functions app without individual code.A Functions app without individual code.

(Image: Drilling / Microsoft)

As a click on the URL of the Functions app proves, the app is already running, but does not yet host its own code.

(ID:46860845)

Ready to see us in action:

More To Explore

IWanta.tech
Logo
Enable registration in settings - general
Have any project in mind?

Contact us:

small_c_popup.png