Definition
What is serverless?
Serverless is a solution to help us build and run service and applications without having to manage infrastructure. When we use serverless architecture, we don’t care about managing and operating servers and runtime but we will focus on developing business projects and optimizing it to get better.
What are Azure Functions?
Azure Functions are a serverless solution that allow us to write less code, maintain less infrastructure and save costs. Instead of worrying about deploying and maintaining the server. Cloud service will provide us with all the necessary methods to keep our application running smoothly and efficiently. So we only focus on developing the business application, the azure function will do the rest.
Azure Function Runtime Version:
-
Currently, Microsoft has provided version 4.x for Azure Function.
-
Supported version in .NET:
-
1.x: Supported .NET Framework 4.8
-
2.x: Supported .NET Core 2.1
-
3.x: Supported .NET Core 3.1
-
4.x: Supported .NET Framework 4.8, .NET 6, .NET 7
-
Beginning in December 2022, Microsoft recommends us to migrate function apps to version 4.x. Because they will stop supporting version 2.x and 3.x.
Support Languages: C#, F#, JavaScript, Java, Python, PowerShell.
Support Environments:
-
Azure Portal: We can develop and test in there. In addition, this is a place for development, staging, and live environment to run and config.
-
Visual Studio, Visual Studio Code: This is a local environment, we can develop and test locally.
-
Azurite: This is an Azurite Emulator for Azure storage locally, we can use it for development. We can learn and install it locally in this link.
-
Cosmos Emulator: This is Cosmos local database, which we can use to store data and every time there is a document change in the Cosmos database, a Cosmos trigger will be executed. We can learn and install it locally via this link
-
Azure Storage Explorer: Upload, download, and manage Azure Storage blobs, files, queues, and tables, as well as locally, Azure Data Lake Storage entities and Azure managed disks. We can download via this link
Bindings and Triggers
What are Bindings and Triggers?
-
Bindings are a way to connect data within our functions. Bindings are optional, there are input and output bindings. Input binding is data that our function will be received. Output binding is data that our function will be sent.
-
Triggers are a way the function can be executed. A trigger defines how a function is invoked and every function has only one way to trigger. Triggers have associated data, which is often provided as a payload of the function.
There are some triggers:
-
Http trigger: A function will be executed when it receives a http request based on data in the body or query string.
-
Timer trigger: A function will be executed when it’s time in schedule.
-
Queue Trigger: A function will be executed when a message is added to an Azure Storage Queue.
-
Blob Trigger: A function will be executed when a file is uploaded or updated in Azure Blob Storage.
-
Cosmos Trigger: A function will be executed when a document is changed in document collection.
In addition, there are some triggers: Event Hub Trigger, IoT Hub Trigger, Service Bus Queue Trigger, Service Bus Topic Trigger, …
For example:
-
Timer Trigger:
- [FunctionName(“TimerTrigger”)] The timer trigger’s name is TimerTrigger
- [TimerTrigger(“5,8,10 * * * * *”)] The trigger will be executed at 5th, 8th, 10th seconds every minute. Schedule expression has format {second} {minute} {hour} {day} {month} {day-of-week}
- Blob Trigger:
- [FunctionName(“BlobTrigger”)] The blob trigger’s name is BlobTrigger.
- [BlobTrigger(“file/{name}”, Connection = “BlobConnectionString”)] With connection BlobConnectionString, the connection string is defined at settings.json. This trigger’s waiting for files to change at file folder (this is folder name) in blob storage to trigger this function.
Proxies
- The Basic thing in Azure Functions Proxies is that allows us to define a single api for multiple function applications.
- Any function application can define a single endpoint as Reverse Proxies for an api or another function application.
- The endpoint can be a function application, Apim or it can be anything else.
- We can use Azure Functions Proxies from version 1.x to 3.x.
- From version 4.x Microsoft recommends us to switch our function applications to integrate with Azure API Management (Apim) instead of Azure Functions Proxies.
- Apim lets us take advantage of a more complete set of features for defining, securing, managing, and monetizing our Functions-based APIs.
- However, we can re-enable Proxies in Azure Function version 4.x. We can learn it via this link.
Monitoring
- Azure Monitor provides us with several ways to monitor our function applications on Azure Portal.
- It helps us to maximize the availability and performance of the application or service.
- Application Insights, Log Analytics, Alerts, and Dashboards are services that are provided inside Azure Monitor.
- In addition, it also integrates in Power BI, Event Hubs, Logic Apps, and API.
- In Metrics Explorer, we can detect the application’s performance and latency or the service in the chart view. It shows the analytics results based on the filters configured on the extensive set of metrics.
- Log Analytics is a tool that helps us to manage Azure Monitor queries. With Log Analytics, we can perform monitoring and diagnostics logging for Azure Logic Apps. We can also query the log for efficient debugging.
- With Alerts in Azure Monitor, we can get the alert report when there is a violation. These Alerts are based on the configured metrics while creating. Each alert only monitors a single entity based on previously configured metrics.
Diagnostics
- Azure Functions diagnostics is an intelligent and interactive experience to help us troubleshoot our function app with no configuration or extra cost.
- When we do run into issues with our function app, Azure Functions diagnostics points out what’s wrong.
- It guides us to the right information to more easily and quickly troubleshoot and resolve the issue.
Pricing
Microsoft provides us 3 kinds of pricing plan:
- Consumption plan: we will be provided with necessary resources by Azure. We only pay when our code runs and we don’t have to worry about resource management.
- Premium plan: We specify a number of pre-warmed instances that are always online and ready to immediately respond. When our function runs, Azure provides any additional computational resources that are needed. We pay for the pre-warmed instances running continuously and any additional instances we use as Azure scales our app in and out.
- App Service plan: Run our functions just like our web apps. If we use App Service for our other applications, our functions can run on the same plan at no additional cost.
For specific pricing information, please refer to this link.
Conclusion
Here is an overview of the Azure Function. It is the first article in a series of Azure Functions. Hope you will enjoy the next articles in this series.
Resources
- Demo source code: Repo’s link
References