Azure Function App: small functions for a big difference

Azure Function App is a cloud computing service offered by Microsoft Azure that allows you to execute small portions of code, called 'functions', without the need to manage the underlying infrastructure. This is an example of a serverless architecture, where developers can focus on code and application logic, while infrastructure management is managed by the cloud provider. In this article, we will spend some time to better understand what it is, how it works and how to start creating a function app from scratch.

What you'll find in this article

  • Azure Function App: What is it?
  • Azure Function App: How does it work?
  • Azure Function App Triggers and Binding
  • Azure App Service vs. Function App
  • Azure Function App: How to create one?
Azure Function App: small functions for a big difference

Azure Function App: What is it?

Azure Function App is a service offered by Microsoft's cloud platform that helps users create and deploy applications quickly. This technology exploits the advantages offered by both cloud computing and serverless computing to allow developers to create complex software solutions in significantly less time than traditional methods.

Serverless computing is a type of computing model in which the developer writes code in the cloud and does not have to manage server instances or the provision of software components, focusing only on writing the code.

In essence, it eliminates all the hassle associated with managing underlying software resources, such as servers and databases. No more worries about managing hardware and, in addition, serverless computing also offers significant cost savings; users only pay for what is used — meaning that when their apps are idle during quieter periods, costs decrease considerably.

By combining Azure cloud services with Function App capabilities, developers can develop apps without worrying about what's happening on the underlying servers — thus achieving scalability and low latency for their creations.

So, if you're looking for an effective way to achieve satisfactory results in your app development, exploring how Azure Function App works might be a good idea, and in the next few sections we'll be focusing on exactly that.

Developing event-based applications, in a personalized way

Azure Function App: How does it work?

Azure Function App is, as we have already said, a cloud service from Microsoft that allows developers to execute code without having to manage the underlying infrastructure. It's ideal for small-scale jobs, allowing you to create event-based programs easily and quickly.

It is based on the same technology as Azure App Service but with additional features such as scalability, triggers and binding — which make solutions developed with Function App suitable for cloud applications that require fast response times or regular updates.

But what is an Azure Function? Basically, it's a piece of code that runs on Microsoft's cloud computing platform and can be written in various languages (JavaScript, C#, or Java, to name a few). It will work the same whether you use Windows or Linux as your operating system.

Functions are triggered by certain events such as an HTTP request or when changes occur in the database, and this avoids having to write additional code for things like calling APIs and running scheduled jobs.

To better understand how Azure Function App works, let's take a look at its key components:

  • First, there are triggers — such as HTTP requests, timers, and queued messages that can be used to initiate functions.
  • Second, we have bindings — parameters that define the data available each time a function is invoked through an input or output binding.
  • Then, of course, there's the main event: the code that executes when its trigger occurs or a binding parameter has been set.
  • Finally, there are resource limitations — determined by the allocation of computing resources for each function performed and by setting restrictions on how many times they can be called in a given period of time.

Function App supports a wide variety of languages such as .NET Core, Java 8/9/10/11/12/13+, JavaScript 6+ (Node + Express), Python 2+/3+, C# Scripts (CSX file), PowerShell version 6 (ps1 file), and even C# compilation (.csx). With Microsoft's 'Function Composition', it is also possible to combine many different linguistic elements in a single program. This allows code composed in different languages to work together, making it possible to carry out increasingly complex tasks in a more productive way.

In addition to these features, Function App boasts an impressive array of features that make it an excellent choice for cloud-native applications on the Microsoft platform.

To name a few, with API management services you can use tools to monitor usage patterns and move data between apps without problems; Durable Entities allow you to set up serverless computing situations with status; cognitive services provide you with artificial intelligence models through APIs; Machine Learning algorithms exploit deep learning (AI); Batch Processing offers integrated self-scalability in addition to integrations with DevOps tools and Docker containers provide additional chance.

Seamless integration between data, artificial intelligence, and DevOps

It also supports serverless architectures and microservice design models — not forgetting custom connectors that give developers quick access to third-party services like Salesforce or Slack without having to write code.

And without forgetting security, Function App provides Authentication and Authorization through integration with Active Directory services and support for Blob Storage to keep log files and other elements used by your application. You can restrict access by assigning particular roles to users/groups (Reader/Collaborator/Owner) and ensure that any confidential data stored on external services such as databases is encrypted accordingly, so that only authorized people can see it.

There are two ways to deploy an Azure Function: through the Azure Portal or using Visual Studio Code in combination with GitHub for version control and distribution tracking. What's crucial here is that you need to specify in which language you want your function to be written and what type of versioning; this ensures that there are no compatibility issues between dependencies and that the triggers work as expected when updates or releases take place.

Even though we don't need a server for our functions, there are still logging features that need to be inspected periodically in case of malicious activity, as well as general performance information, such as how often functions are called, etc. All of these considerations keep the data secure and help establish real knowledge of what happens when the function is put under stress under different circumstances.

Did you know that we help our customers manage their Azure tenants?

We have created the Infrastructure & Security team, focused on the Azure cloud, to better respond to the needs of our customers who involve us in technical and strategic decisions. In addition to configuring and managing the tenant, we also take care of:

  • optimization of resource costs
  • implementation of scaling and high availability procedures
  • creation of application deployments through DevOps pipelines
  • monitoring
  • and, above all, security!

With Dev4Side, you have a reliable partner that supports you across the entire Microsoft application ecosystem.

Azure Function App Triggers and Binding

Now that we've looked at the anatomy of Azure Functions in general, let's take a closer look at triggers and bindings to better understand how they work.

Triggers are what cause a function to execute. They define how the function is invoked and can be based on a variety of events or schedules. Every function must have exactly one trigger. The type of trigger used determines the data available for the function and the environment in which it is executed.

Common types of triggers include:

  1. HTTP Trigger: Invoke the function through an HTTP request. This is useful for creating APIs or responding to webhooks.
  2. Trigger Timer: Invoke the function based on a schedule defined using a cron expression. This is useful for tasks that need to be done periodically.
  3. Trigger Blob: Invoke the function when a new blob or updated blob is detected in a specified Azure Blob Storage container.
  4. Trigger Queue: Invoke the function when a new message is found in an Azure Storage queue.
  5. Trigger Service Bus: Invoke the function when a new message is available in an Azure Service Bus queue or topic.
  6. Trigger Event Hub: Invoke the function when events are delivered to an Azure Event Hub.
  7. Trigger Cosmos DB: Invoke the function when changes are made to documents in an Azure Cosmos DB database.
  8. Trigger Event Grid: Invoke the function when an Event Grid event is received.

Bindings provide a way to connect your function to other services and data sources without having to write custom integration code. They abstract the underlying complexities and allow developers to focus on business logic.

Bindings can be input bindings (to bring data into the function) or output bindings (to send data from the function) and include:

  1. Binding Blob Storage
    • Input Binding: Reads a blob and provides its contents to the function.
    • Output Binding: Writes data from the function to a specified blob.
  1. Binding Queue Storage
    • Input Binding: Reads messages from an Azure Storage queue.
    • Output Binding: Writes messages to an Azure Storage queue.
  1. Service Bus Binding
    • Input Binding: Reads messages from a Service Bus queue or topic.
    • Output Binding: Writes messages to a Service Bus queue or topic.
  1. Binding Cosmos DB
    • Input Binding: Retrieve documents from a Cosmos DB collection.
    • Output Binding: Writes documents to a Cosmos DB collection.
  1. Binding Table Storage
    • Input Binding: Read entities from an Azure Table Storage.
    • Output Binding: Writes entities to an Azure Table Storage.
  1. HTTP binding
    • Input Binding: Retrieve HTTP request data.
    • Output Binding: Send HTTP response data.

But how do they work together specifically? A first example involves an HTTP Trigger and an Output Binding Blob Storage. In this scenario, an HTTP request uploads a file to Azure Blob Storage. The function is then invoked by the HTTP request and the contents of the file are stored in a blob.

A possible second scenario concerns a Trigger Timer and a Cosmos DB Binding. Let's imagine we need to implement a scheduled activity that runs every night to aggregate data from various documents into a Cosmos DB collection. In this case, the function is invoked by a Timer and interacts with Cosmos DB using both input and output bindings.

Finally, a third possible example could involve a Trigger Queue and an Output Binding Service Bus. In this case, a function processes messages from an Azure Storage queue and forwards them to a Service Bus queue for further processing. The function is invoked by new messages in the Storage queue and uses an output binding to send messages to the Service Bus queue.

Azure App Service vs. Function App

Among the enormous amount of services provided by Azure, several are dedicated to the execution and writing of code for apps. Often, similar nomenclature and apparently interchangeable features can confuse first-time users of the platform, who may be perplexed when choosing the right tool to solve their problems.

In this section, we will briefly dwell on the difference between Function App and another Azure service designed for App development, namely App Service, both two Azure offers designed to execute code, but with different purposes and usage models.

Azure Function App is, as we have already seen, a serverless execution platform where the code is executed in response to specific events, such as an HTTP request or a message in a queue, and Azure automatically allocates the necessary resources.

Instead, Azure App Service is a service that allows you to host web applications, APIs and backend services on managed infrastructure. Although it offers automatic scalability, the execution model is more traditional than Function App and, in this case, you have greater control over the execution environment, being able to configure the runtime, manage sessions and maintain the state of the application between requests.

The main difference therefore lies in the approach to infrastructure management and usage: Azure Function App is oriented to executing code reactively and on demand, without worrying about servers, while Azure App Service is a platform for hosting more structured web applications, with a greater emphasis on control and configuration of the execution environment.

App Service is therefore more suitable for medium or highly complex web applications that need to be always active and ready to respond to user requests, ensuring continuous availability, where Function App is particularly useful for short and punctual tasks, where the code is executed only when required, with dynamic scalability management, an ideal approach for scenarios such as the processing of events, the management of triggers and the automation of tasks that must react to external changes or inputs.

Azure App Service overview

Azure Function App: How to create one?

But why limit ourselves to describing its ease of use when we can test it personally? Now that we have a clearer idea of its main components and how it works, it's time to test Azure Function App in the field and we'll do it by creating a small test application.

Prerequisites for creating a Function App

There are a few prerequisites we need to be aware of before creating an Azure Function App:

  • A valid Azure account with a subscription.
  • A Service Plan within which the function must be created and executed. There are usually two types of service plans:
    1. Piano App Service: allows the user to continuously execute code on a virtual container with a set of allocated computational resources. Unlike the Consumer plan, there is no timeout for functions.
    2. Piano Consumer: charges only for the duration that the function is performed. A timeout is also set for these functions, which by default is set at 5 minutes and can be extended to a maximum of 60 minutes.
  • An Azure Storage Account, which will be linked to the Function App and can be used to store information such as logs and manage triggers, etc. We can also use this storage account to store configuration files for this function.

Create the function

There are three ways in which we can create a Function App:

  • Using the Azure portal
  • Using the Azure CLI (Command Line Interface)
  • Using a code editor, such as Visual Studio Code

In this tutorial, we'll explore the first option, which is using the Azure portal. We access the Azure portal (accessible by visiting https://portal.azure.com) and we're looking for Function App.

The Function App dashboard will open, which appears as shown below. Since no functions have been created, the dashboard is empty. If you had previously created functions (and these are still active), a list of all the available functions created in this account will be displayed.

Let's click on Add at the top, or click on the button Create Function App to start creating the application.

Azure Functions dashboard

On the next page, we'll need to provide some configuration details about how we want to create the function and its name, along with some other parameters. The first option here is to select the subscription account under which the function will be created. It can be considered as a logical grouping for billing management. In this case, we have a default subscription, which we will select to proceed.

The next parameter is to select the resource group. The resource group is also a logical group and can be used to group various resources that belong to the same solution. You can select an existing resource group or proceed to create a new one as follows.

New resource group creation detail

Once the resource group has been created, we can proceed with the other parameters. The next important point is to provide a valid name for the function. This name must be globally unique, as it will be used as part of the base URL.

Let's select the option Publish like Code and the runtime stack like .NET Core. You can choose any other runtime stack based on your preferences.

Finally, you will need to select the region where you want to distribute your function. As a good practice, the function should be deployed in a region close to where your customer is located. In this case we will use the region West Europe.

Data entry detail

Once we have filled in all this information, we click on Next: Hosting and let's configure the relative parameters.

Here we must define the details of the storage account, which will be used by our function. If you already have a storage account, you can safely use that one or create a new one.

New storage account creation detail

Once the storage account has been created, we can select the operating system and plan for the function. The default operating system for .NET Core is Windows. For the plan, we will select the Piano Consumption, which will be scaled based on when the function is activated and will be charged based on the execution time.

Plan and operating system selection detail

Then let's click on Next: Monitoring to configure monitoring parameters. Here we will be asked if we want to enable Application Insights or not. For this tutorial, this option will remain disabled as it is not an integral part of the topic covered. So let's click on No and let's go further.

Application Insights Enabling Detail

At this stage, you can click Review + Create to create the function as specified. All information will be verified and then the details will be displayed for your review. Once you've reviewed the details on this page, go ahead and click Create.

Review + Create screen

The process of deploying the function may take some time, depending on the resources available. Once the deployment is complete, you'll see the following information appear on the dashboard.

Deployment completion screen

Verifying and writing code

Once the Function App has been created, the next step is to verify the URL of the function and confirm if the app is up and running. Click on the URL and we'll be redirected to the Function App homepage.

Application URL detail

The page looks similar to the figure below. This means that the Azure Function App is now up and running.

URL page

Now that we know that our function is active, it's time to write the code that we need to distribute in this function. When creating the new feature, it's important to keep the following two points in mind before proceeding:

  • Trigger Type — Defines how the function should be called; it can be an HTTP call, a change in a database table, or any other event that can trigger a function.
  • Authoring options — Users can choose how they prefer to write the code for this function. They can write the code using the code editor built into Azure, or they can choose a preferred desktop code editor, such as Visual Studio Code or Sublime Text.

Click Function and then select Add. A list of templates will appear on the right; select HTTP Trigger.

Selecting HTTP Trigger

Once the trigger type has been selected, we provide details about the function. Let's enter a name for the function and the level of authentication. In this case, let's select Anonymous as an authentication level and we click Create Function.

Function name detail and permission level

The function will be created and deployed within a few minutes, and we can verify the details as follows.

Function created

Let's click on Code + Test to view the code provided.

To test this feature, let's click on Test/Run. A panel will appear on the right where we will have to set the HTTP method to GET. In addition, let's add a parameter Name to the list of queries with a value of your choice. In this particular case, we used a random name. Let's click on Run once completed.

Function test

Conclusions

The cloud landscape is offering new possibilities day after day to developers who want to exploit its potential for writing and distributing their applications.

In this context, Azure (which we remember is the second most used cloud platform in the world), with its amount of services, is positioned, thanks to offers such as those of Azure Function App, as an incredibly solid choice for all those developers who want to exploit the potential of serverless computing and application development, disconnected from age-old concerns related to the underlying infrastructure and focus only on writing their apps: the really important and creative part of their work.

All that remains is to invite you to try it and see if the Microsoft solution based on these small code fragments can also make a big difference for you in terms of time and resources.

FAQ on Azure Function App

What is an Azure Function App?

An Azure Function App is a serverless cloud computing service provided by Microsoft Azure. It allows developers to execute small pieces of code, called "functions," without managing the underlying infrastructure.

How does Azure Function App work?

Azure Function Apps operate on event-based triggers, automatically scaling based on demand. The service is ideal for tasks like HTTP requests or database changes.

What languages can be used with Azure Function App?

Azure Function Apps support multiple languages, including JavaScript, C#, Java, Python, and PowerShell.

What are common Azure Function App triggers?

Azure Function App triggers include HTTP requests, timers, Azure Queue messages, and Cosmos DB changes.

How does Azure Function App differ from Azure App Service?

Azure Function App is optimized for executing small, event-driven tasks without server management, while Azure App Service is designed for hosting full web applications with more control over the execution environment.

How do you create an Azure Function App?

Azure Function Apps can be created via the Azure Portal, Azure CLI, or code editors like Visual Studio Code.

What are bindings in Azure Function App?

Bindings in Azure Function Apps allow functions to connect to other services, like Blob Storage or Cosmos DB, without custom integration code.

What are the two main types of Azure Function App service plans?

The two main service plans are the Consumption plan, which charges based on execution time, and the App Service plan, which runs continuously without timeouts.

How is Azure Function App beneficial for developers?

Azure Function App simplifies infrastructure management, allowing developers to focus on writing code, making it efficient for small, scalable, and event-driven applications.

Find out why to choose the team

Infra & Sec

The Infra & Security team focuses on the management and evolution of our customers' Microsoft Azure tenants. Besides configuring and managing these tenants, the team is responsible for creating application deployments through DevOps pipelines. It also monitors and manages all security aspects of the tenants and supports Security Operations Centers (SOC).