In this article, I want to get you excited about the possibilities that Azure functions open up because I think this is a technology, the potential to transform the new way you architect your applications. Also in this article, I want to discuss the concept of serverless computing because you can process the events with serverless code using Azure functions.
What are Azure Functions ?
Azure Functions are the serverless model to accelerate the development experience. Events and code are the main building blocks of an Azure Functions. Azure Functions are easily scalable based on demand and pay only for the resources you consume.
Benefits of Azure Functions
- Simple and fast development –Just write the code that responds to the event and eliminates the boilerplate code that you write to connect these events. You can write code even in the portal.
- New pricing model –WebJob , Azure Web Apps , Virtual machine and Cloud Service need at least one continuously running server. But Azure Function has the option to select pay as you consume. In other words , you only pay when your code is running. So if your Function is listening on a queue and no message ever arrived , then you will pay nothing.
- Powerful like Azure Web App –Features like continuous integration, Kudu console, custom domain, SSL support and much more
- No Server to maintain
- Automatic Scaling
What is serverless computing ?
Serverless computing actually requires a server. The name “Serverless computing” is used because the server management and capacity planning decisions are completely hidden from the developer or operator. Azure Function is based on serverless computing architecture.
Building the first Azure Function
One of the coolest feature is that we can create an Azure Function and try without an Azure Account. Click here to navigate to portal and click on “try it for free” option. A page will be displayed to choose the scenario and the programming language. Here I’m selecting Webhook + API + C# option and click on “create this function” button. This will ask for an authentication. You can authenticate using GitHub, Microsoft, Facebook and Google account. After the authentication, with in seconds, a brand new Azure Function will be created.
On the top header, we can see a timer is running because of this “free trial only for 1 hour”. The C# code which we are seeing on the page is on run.csx file which actually a C# script file. On the top there are buttons for saving the code, run the code and even an option to get the public URL. Try editing C# and click on save button to compile your code and make it ready for the run.
In the test tab which is on the right side of the window provides a live testing experience. You can pass the request body to your function and function will return the response in the output windows. The following screen shows my Azure function request and response in real-time.
In the proceeding example, the Azure function works with a user event and if you want to schedule a task then choose the timer option instead of Webhook + API. Azure functions has built in templates to get you started with key scenarios like BlobTrigger, EventHubTrigger, Generic webhook, GitHub webhook , HTTPTrigger, QueueTrigger , ServiceBusQueueTrigger , ServiceBusTopicTrigger , TimerTrigger etc