Yes, the immediate question can be what exactly is this Azure Function? In simple English, it is running a function in a cloud environment. It enables us to create a serverless application in a Microsoft Azure environment. Consider a scenario where we know the problem, we know the code that can fix the problem, and we don't want to worry about resources that execute this code. This is the easiest way to focus on logic and business and enhancing the scope of productivity. The biggest benefit is we only need to pay for what we use. Let's understand what exactly in terms of features are provided by the Azure Functions and Azure App Services:
Azure App Services (Web Apps, Mobile Apps), and Functions support different languages and frameworks, DevOps capabilities, scaling, load balancer and etc.
Azure Functions is a service provided by Microsoft for serverless computing. The Azure function is a combination of code plus events plus data. Azure Functions is open source and available on GitHub:
Let's see where Azure Functions is placed in Cloud Service Models in the following figure:
Azure Functions are similar to Azure Webjobs with some differences such as scaling policies, trigger events, and language support. We don't need to worry about infrastructure for execution of the piece of code or function. It is like a FaaS. We can execute Azure Functions in response to events as well.
The languages that are supported are C#, F#, Node.js, Python or PHP, batch, bash, or PowerShell.
There are two types of pricing plans available in the Azure Functions:
- Consumption plan: When we execute functions, Microsoft Azure provides all the resources. We don't need to worry about resource management, and we only pay for the time that our functions are executed. The consumption plan pricing includes a monthly free grant of 1 million requests and 400,000 GBs of resource consumption per month. Free grants apply to paid consumption subscriptions only.
- App Service plan: This executes functions just the way we execute Azure App Services. We can utilize the same App Service plan created for any application and execute Azure Functions on it without any extra cost.
Having App Service plan as the host for Azure Functions provides lots of benefits that are available with Azure App Services. We can utilize remote debugging, deployment slots, continuous deployment, vertical scaling and horizontal scaling, auto-scaling, and so on. If we use the Azure App Service, then it is a multitenant scenario. If we want to utilize a dedicated environment, then we can utilize the App Service Environment that is a dedicated service from Microsoft Azure, where we can host a function in a virtual network and configure network security groups (NSGs) for an enhanced level of security.
Triggers and bindings are the core of Azure Functions. It allows us to write a function to respond to events that occur in the Azure or other services. As the name suggests, trigger indicates how the function should be invoked and bindings are related to data. Azure Functions can have only one trigger associated with it. Bindings are the connection to the data from within the code available in the function. Unlike triggers, functions can have one or more input and output bindings.
The following table shows the triggers and bindings that are supported with Azure Functions:
HTTP (REST or Webhook)
Azure Event Hubs
Queues and topics
Azure Service Bus
Azure Mobile Apps
Azure Notification Hubs
Twilio SMS Text
Let's try to get to grips with Azure Functions quickly:
- Go to https://functions.azure.com/try.
Webhook + APIas a scenario and select
- Click on
Create this function:
- Select an auth provider.
- Select any suitable authentication method and sign in with it:
- Wait for few seconds until a free trial fo Azure Functions is ready:
- The sample script is ready for
- Click on
Teston the right side of the browser window. In
Request body, provide the
- Click on
Runand scroll down.
- See the
So, we have just executed the simple Hello World function. We will execute Azure Functions in a proper Azure subscription in later chapters.
The following are some of the benefits of Azure Functions:
Before we jump to Azure Functions, let's understand some basics of Microsoft Azure cloud. We will discuss the key components and services of Microsoft Azure in the next section.