Serverless Computing has become a trending area in Azure than ever before. Basically, Serverless Computing is completely abstracting away the required resources from your concerns. It acts in an event-driven manner, resources are utilized only when you want them to, those are not up and running when you are not using them. So you are getting billed for only for what’s being used. You don’t have to worry about anything else.
When talking about Serverless Computing in Azure, as of today Azure provides following 3 set of features.
- Functions - Serverless Compute
- Logic Apps - Serverless Workflow
- Event Grid - Serverless Events
In this post, let’s see how we can get started with Azure Functions.
First, open up the Azure Portal. Go to New and search for “functions”. And click on Function App.
|
Function App |
From the next panel, click on Create.
|
Create |
From the next screen, fill in the details as required. For the Hosting Plan, let’s go ahead with the Consumption Plan because we can then get billed per execution of our functions.
|
New Function App Details |
Once the function app is created. Find the created function app by going to More services and searching.
|
Find Function Apps |
And you should see all your function apps.
|
Function App |
Now when you can click on created function app, you will something like below.
|
Function App: Overview |
You can find the function app URL under Overview tab. If you click on the URL, an application will open, just as an App Service.
|
Function App |
Function apps’ Settings is under Platform features.
|
Function App: Platform Features |
Right now to get us keep going, let’s create a Function. Click on Functions and then New Function as below.
|
New Function |
You are presented with a set of templates.
|
Select Template |
All the languages available are as follow (please note, for some of the languages all the templates are not available).
|
Available Languages |
First, let’s create an
HTTP Trigger.
|
New HTTP Trigger |
I have selected Language as C#. For the Name, you can give whatever the name you want. And then we need to select the Authorization level.
Let’s go ahead with Anonymous for the purpose of the demo.
Once the function is created, you are presented with a page with a csx file. csx stands for C# Script file. Here you can edit the body of the Run method. Please note, you need to have the method signature as it is.
On the Test panel, let’s change the HTTP Method to GET and add in a new query parameter ‘’name”. Give it some value and click on Run, and you can see your Azure Function is running.
|
run.csx |
You can get the function’s URL as above, let’s just copy it into a notepad.
To make the demo nicer, let’s add another function, this time a Timer trigger.
|
New Timer Trigger |
I have selected C# as the Language, some Name and you can see the Schedule is expressed as a CRON expression. I have updated the CRON expression to every second.
Like the previous function, you will see the Run method, here let’s modify the method to send an HTTP GET to our previously created function.
using System;
public static async Task Run(TimerInfo myTimer, TraceWriter log)
{
var client = new HttpClient();
var response = await client.GetAsync("{FunctionUrl}?name=John");
var result = await response.Content.ReadAsStringAsync();
log.Info($"C# Timer trigger function executed at: {DateTime.Now}, Result: {result}");
}
You can replace the {FunctionUrl} with the URL we have copied over to notepad. And let’s run it. You can see our Timer trigger function is executing every second calling the HTTP trigger function.
|
Timer Trigger Running Log |
Isn’t it nice or what?
Happy Coding.
Regards,
Jaliya