Getting Started with Azure Functions for VS 2017

There was a heap of awesome things announced at Microsoft Build 2017 , Scott Hanselman  has a great roll up of the most important developer announcements here.

One that I have been spending some time getting up to speed on is the Azure Functions Tooling for VS 2017. Here are a few tips I have learnt.

Firstly as of April 2017 the tooling is in preview mode. That means you can’t just add it to a regular installation of Visual Studio , you can however run the preview side by side with the main version assuming you have enough disk space. The options for running Visual Studio Preview are covered well here.

The specific version of Visual Studio and a link to the preview tools for Azure functions are covered in this article as are the steps for creating your first Function.

You need to think carefully about what sort of Function you want to create as there is no wizard or property selection that allows you to easily change to another type. It is possible to do manual updates to change the properties but generally better to select the correct template initially.

The current options are:

  • BlogTrigger
  • EventHubTrigger
  • GenericWebHook
  • GitHubWebHook
  • HttpTrigger
  • HttpTriggerWithParameters
  • QueueTrigger
  • ServiceBusTopicTrigger
  • TimerTrigger
  • FaceLocator
  • GitHubCommenter
  • HttpGetCRUD
  • HttpPostCRUD

The first thing you need to do before you run the function is set the AzureWebJobsStorage key in the local.settings.json file. This is necessary for all functions apart from the http based ones to be able to run locally.

Selecting the correct template gives an easy way to configure the correct input trigger.
Azure functions also has output bindings , all the different options are covered here. however how to do this when using VS 2017 is a little bit different.

Essentially you just add in the the correct output item to the run function and a connection string in local.settings.json so it can run locally.

For example a function that is triggered by timer would initially look like:

public static void Run([TimerTrigger(“0 */5 * * * *”)]TimerInfo myTimer,  TraceWriter log)

To add an output trigger for service bus it would then look like the below :

public static void Run([TimerTrigger(“0 */5 * * * *”)]TimerInfo myTimer, [ServiceBus(“evbsbtest”, AccessRights.Send, Connection = “sbconn”)] ICollector<string> outputSbQueue, TraceWriter log)

This also requires adding a using  statement for Microsoft.ServiceBus.Messaging  for the access rights object.

Another item that I hit was an error when I added a service bus binding starting to run the function  caused this error  “The following 1 functions are in error: Can’t figure out which ctor to call” . After trying in vain to debug it I released that this was actually a bug in the Azure Functions SDK as noted here.

In my project I then clicked manage Nuget packages and sure enough an update was sitting there waiting for me to install.  Given the alpha status of this package it is quite likely it will be frequently updated as issues are found.  Hence well worth checking the open and recently resolve issues if you do hit a problem !

The final tip I have is that as Azure functions are easy to write and new and shiny I find myself very easily adding way too much into a single function. Hence I find I have to constantly re-evaluate whether I am breaking best practice.  In several cases already I have ended up refactoring what I thought would be a single function into multiple and adding in a logic app to assist with orchestration to keep the functions stateless and short running these and other Azure functions best practices can be found here







Office 365 Groups – Ignite Aus wrap up

During my session on managing groups at Ignite Australia on deploying and managing groups I referenced this great blog post by Wictor Wilen which explains all the details of how to script changing the settings via script at the Azure AD level.

For my provisioning demonstration I also used the Office 365 PnP-Powershell commands – the installer for the current version of these are here  and specifically the New-PnPUnifiedGroup command. To have this command you need to be on at least the Nov 2016 release of the commands.

More information on development samples such as how to create tabs and integrate bots into Microsoft teams are explained on the teams dev center. I also found this overview of connectors to be useful although some of the UI has changed recently which means if you follow the demonstrations steps in your tenancy you will need to adapt a couple of the steps.  The major change is that for basic connectors you can select the webhook connector now straight from the main connector UI as that is now GA.

During the session I also mention an earlier session in the conference which went into the roadmap for Groups, definitely worth a view to get across the new features due to arrive soon.

Also for more information on what to use where in regards to groups , teams and yammer this session is well worth the watch