Close

Latest gotchas for Azure Functions

Delete a function:
You can remove a function from a function app via the Azure Portal. Select the function in the Function App. Select the Manage menu en click [Delete]. Very easy. I just didn’t know it was possible.

Timer trigger:
If you want to build an Azure Function that is executed let’s say every five minutes, you can use the Azure Function template TimerTrigger – C#. To specify the interval, you need to use cron expressions. An explanation on cron expressions can be found: here. Examples of cron expressions are also given on the Azure Portal page where you specify the trigger for the function.

Call a Logic App from an Azure function
Use the HttpClient object to send a post request. An example is shown below:

using System;
using System.Threading.Tasks;
using System.Net.Http;
using System.Text;

private static string logicAppUri = @”https://prod-03.westeurope.logic.azure.com:443/workflows/…”;
private static string content;

public static void Run(TimerInfo schedule, TraceWriter log)
{
DateTime endDate = System.DateTime.Now;
TimeSpan fiveMinutes = new TimeSpan(0, 0, 5, 0);
DateTime startDate = endDate – fiveMinutes;
string formattedEndDate = endDate.ToString(“yyyy-MM-ddTHH:mm:00.000Z”);
string formattedStartDate = startDate.ToString(“yyyy-MM-ddTHH:mm:00.000Z”);
string regionCode = Environment.GetEnvironmentVariable(“RegionCode”);

using (var client = new HttpClient())
{
content = $”{{‘regioncode’: ‘{regionCode}’, ‘from’ : ‘{formattedStartDate}’, ‘to’ : ‘{formattedEndDate}’}}”;
var response = client.PostAsync(logicAppUri, new StringContent(content, Encoding.UTF8, “application/json”)).Result;
}
}

One addition: Azure works with UTC datetime out-of-the-box. Often you want to use local datetime however. This is the code I added at the start of the function:
var cetZone = TimeZoneInfo.FindSystemTimeZoneById(“Central Europe Standard Time”);
DateTime endDate = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, cetZone);

Use configuration settings
An example can already be taken from the above example: string regionCode = Environment.GetEnvironmentVariable(“RegionCode”). To specify the application settings, click [Function app settings] in the bottom of the menu. Click either [Configure App Settings] or [Go to App Service Settings] and you can specify your application settings like RegionCode.

 

Leave a Reply

Your email address will not be published. Required fields are marked *