Build 2016 got me pretty excited and I therefore decided to experiment a little with Azure Functions. Many new App Services features have been showcased, amongst a lot of other existing topics. But what really got my attention was Azure Functions, especially Logic Apps integration.
Azure Functions the basics
Azure Functions, is a lot more than I’m covering right here. The people at Azure describe it as an event driven, compute-on-demand experience. Just to simplify things; You basically write small snippets of code (C#, PHP, JavaScript, F#, Python) that can be called from other Azure resources or externally just like an API App with less overhead. But in addition to this, it’s also possible to let Azure execute your functions based on Azure Events or a timer.
As far as I understood… Azure Functions is hosted in Azure Web Jobs on steroids. And billing will be based on computing time or your current Service App subscription. This depends on how the service has been configured. There is actually a lot more (deployment, source control, authentication etc.), but I will leave it for now. The following resources can be used to help you understand the technology in great detail:
- Announcement blogpost: https://azure.microsoft.com/en-us/blog/introducing-azure-functions/
- Introducing Azure Functions (video): https://channel9.msdn.com/Events/Build/2016/B858
- Azure Functions Under the Hood (video): https://channel9.msdn.com/Events/Build/2016/T692
Function Apps and Logic Apps
The Functions are interesting for everyone using Logic Apps due to the following reasons:
Reason 1 – Coding and deploying Azure Functions is a lot simpler compared with full API Apps / Web API based projects. Now, for complex logic I wouldn’t be using Azure Functions. However, they would be ideal for small Logic App Workflow Definition Language helper function.
Reason 2 – The trigger functionality on Azure Events part is something which might be reused or consumed within Logic apps just like a Connector Push trigger. This will be more interesting in the future, because I believe that the Azure Functions ecosystem will have a wider and more active group of users.
Simple Demo – Calling Azure Functions in Logic Apps
A demo is perhaps the best way to see how this all comes together. I’m assuming that you already have an App Service environment configured.
Step 1 – Within the Azure Portal, click NEW > and search for “function App”. Select the Function App within the details blade and click on CREATE.
A new blade will show up where it’s required to provide the name, Subscription, Resource group, storage account and App Service Plan. The plan called CLASSIC will make use of the resources in your current service plan as DYNAMIC will be hosted on a different computing environment. DYNAMIC also uses a billing by compute time model.
Note: Azure will also create an Application insights environment for your Function App automatically.
Step 2 – Locate and click on your Azure Function App. This will open a new blade in which you can create new Functions as well as monitor and configure your Function App environment (Continuous Integration, Authentication, CORS, API Definition and more).
For the demo, I will create a simple Function which accepts data input, performs some complex operations and return the result.
Step 3 – Click on New Function > Select the “Generic WebHook – C#” template.
Replace the default code with the sample provided below and save the function.
Note: It’s not required to copy the Function Url because Logic Apps contains a special Action that is able to do this for you..
Step 4 – Create a new Logic App > And open this Logic App within the designer. Add a manual action first and add another action. Within the Actions selection screen make sure to alter the selection Show Microsoft managed APIs to Show Azure Functions in my subscription. A list with all Azure Function Apps (the Azure Functions container) will appear. Select the function created in step 3.
Step 5 – I’m just providing the sample JSON data as can be seen in the image below. This to keep the demo simple. At this point the workflow can be saved and executed. The output result will be as following;
Below the result as returned by our Azure Function.
Conclusion
This is just a very simple example however, perfectly demonstrates the power of Azure Functions. As mentioned before, Functions do support many other advanced scenarios and options.
Recent Comments