Introduction to Azure Functions
Azure function is a service provided by Azure to run a small piece of code in the cloud. Functions are executed in a serverless cloud computing manner. The developer needs to code snippet and deploy in the cloud, of course, it runs on the server but the management of the server is not the responsibility of the developer, it is taken care of by Azure. Functions can be developed in any choice of language like python, java, etc. Functions also promote code reusability as it doesn’t depend on the application. It is a simple piece of code developed to perform a task. We can call Azure functions as Function as a service provided by azure.
Why do we Use Azure Functions?
Firstly, Azure functions are executed in a serverless manner, so the developer doesn’t need to worry about server management. It provides as with the combination of IAAS and PAAS services. Functions can be developed using web tools or build tools of the developer’s choices and are very easy to deploy. Supports a variety of programming languages such as C#, Java, Python, NodeJS, etc. Functions can be triggered very easily based on any event such as blob container creation, HTTP request, Using Cron, Queue trigger, Webhook trigger, time-based trigger, etc. Also with the use of development and deployment, it also includes security provided by Azure such as Azure Active Directory. All the features make Azure Functions very popular when it comes to serverless cloud computing.
How to Write Azure Functions?
It is very easy to develop azure functions using below steps:
Step 1: Go to the Azure portal.
Step 2: Click on + icon to add a resource.
Step 3: Choose the function app from resources.
Step 4: Provide parameters while creating azure functions.
Few parameters are marked with an asterisk are mandatory such as:
- Resource Group: In which group resource needs to be created.
- Subscription: Account subscription to be used for function app creation.
- Function App Name: Choose app name it should be unique across Azure.
- Publish: Either code or docker can be deployed.
- Runtime Stack: Choose runtime stack according to your favourite programming language.
- Storage Account: Choose storage account required for function app processing. You can either choose an existing storage account or can create a new one.
- Operating System: Choose an operating system based on the requirement. It can be either Windows or Linux.
- Plan: There are 3 types of plan while hosting a function. The default is the Consumption plan. This is pay as you go type of plan. The cost will be charged only when the function runs. The hosting plan needs to be decided based on the requirement, such as function scalability, Vnet connectivity, etc. There are 3 types of plans:
1. Consumption Plan: This is a pay-as-you-go type of plan. The cost will be charged only when the function runs. Resources are dynamically added or removed based on the events, so azure takes care of scalability. Execution time out can be configured based on the requirement. Multiple apps running in the same region can consume the same plan. Billing can be done based on the number of executions, memory used, and execution time.
2. Premium Plan: It is basically an extension of the consumption plan with some additional provided features such as Vnet connectivity, unlimited execution duration, Perpetually warm instance. In the premium plan, billing is done based on the number of cores used per second, the number of pre-warmed instances. Also, there should be at least one pre-warm instance all the time. This means there is a specific monthly cost that will be charged regardless number of executed apps.
3. Dedicated App Service Plan: As the name suggest this is a dedicated service plan. It means there are a dedicated set of VM’s for the function app. You can also choose your personal image on which functions need to be executed. For scalability, More VM’s can be added at runtime manually or Autoscaling can also be enabled.
Step 5: Click on review and create to review the configurations.
Step 6: Click on create a function to deploy the function.
Step 7: Go to your resource group and you will see a function app that will be created with the name provided as above.
Step 8: Choose the function app, choose in-portal and create an HTTP triggered function inside the app.
Step 9: The function will be triggered by the HTTP request.
Step 10: When the function is created there will be a URL provided.
Step 11: Paste URL in the browser address bar and you will see the response based on the code written in function.
Advantages and Disadvantages
Given below are few advantages and disadvantages explained.
- The biggest advantage of this is its serverless execution, the developer doesn’t need to worry about the management of the server.
- Supports a variety of programming languages such as python, java, c#, NodeJS, etc.
- Supports all security services provided by Azure such as Azure active directory etc.
- Very easy to trigger functions based on various events.
- It can be developed by a web-based tool or any other build tool based on developer choice.
- As it is a very lightweight code, provides smooth execution.
- Vendor-lock is the biggest drawback of this functions.
- It is very difficult to run code deployed in Azure function outside the azure environment.
- As the language used in function app such as java, NodeJS, etc are not specialized but code to establish a connection between resources is specific to azure.
This has been a guide to Azure Functions. Here we discuss the basic concept along with uses, how to write azure functions, and advantages and disadvantages. You may also have a look at the following articles to learn more –