Azure Functions & Triggers
The course is part of these learning paths
This course is an introduction to Azure Functions. It explains how Azure Functions are little bits of your application logic that live in the cloud. The course includes how to activate—or what we call trigger—your Azure Functions, how to pass data to and from them, and also how to tie different Azure Functions together using an extension of Azure Functions called Durable Functions.
This course provides hands-on demonstrations of how to create different kinds of Azure Functions, how to create bindings to other Azure Services from those functions, and how to create a Durable Function to manage state from one Azure Function to the next.
If you have any feedback related to this course, please contact us at email@example.com.
- Create Azure Functions with different types of Triggers
- Implement input and output bindings to different types of data resources
- Create Durable Functions to orchestrate related Azure Functions
- Log the results with Dependency Injection
Software developers who want to learn how to implement Azure Functions as a part of their cloud software design.
To get the most out of this course, you should have some experience will the following:
- Event-driven programming
- Servers and APIs
- Coding with C# and JSON
- Project creation in Visual Studio
The GitHub repository for this course can be found here.
The Durable Functions equivalent of hello world, would be to create a set of activity functions that could be executed from your orchestrator function. So that's what we're going to do in this exercise, we'll even create our own as Azure Function outside of the template, and we'll have a value returned from that function that we can then pass on. In this case, we'll be passing it back to the same function to show a change in value, but we could take that value and pass it along anywhere, thus maintaining state which is usually very challenging in the serverless world of Azure Functions.
To add a Durable Function to your Azure Functions project, just right click on the project name and do Add New Azure Function. We'll actually go ahead and name this one FunctionDurable since we know that's what we're gonna do with it, and then the list of Azure Function Types pops up, and you will see that Durable Functions Orchestration is in the list. So we just click Okay, and Visual Studio will do its thing and create for us our basic Durable Functions template, which is going to include three different types of functions in it. It will include first our orchestrator function that will be responsible for calling all of the other activity functions. And then there will also be an HTTP trigger function, that is going to be how we are going to activate our orchestrator function in the first place, meaning that yes, at last, we will finally be executing one of our Azure Functions using the much mentioned HTTP trigger as if our function was an API endpoint.
So first, just to make sure that we can see what's going on here, we're expecting some text to be written to the screen when we run our orchestrator calling our activity functions. So let's just run the Azure Function and make sure that everything is looking good inside of our Durable Function. As usual, Visual Studio pops up your console so that you can see all the logging. We're going to need some important bits of this, you can see right there durable task has been created. And you can see in the green there just flashing by us was a critical bit of information that we need. This is our actual HTTP endpoint that we would need to use from a browser to call our Azure Function.
So we'll go ahead and do a quick copy on that, we'll pop open a new window, we'll paste that in, and we'll run our Durable Function. You can see we got something back from running it so everything's looking good. And when we come over to our console, we can see it's full of a lot of stuff, including here's a hello to London, here's a hello to Seattle. And so we can see that each of the activity functions within our Durable Function has run properly.
So now let's take advantage of some of the power of that so that we can actually pass some values from one Durable Function to another and see that important sequence happening. So let's just create a little bit of space here. And then I have a pre-created function that I can drop in that does nothing but add five to the value that we pass in. So here's x equals five, here's the logging information telling us that we're gonna be adding that value to whatever the value that is passed in. And then we're gonna be going ahead and returning that value.
So how would we get access to some of that stuff up here inside of our orchestrator function? Let's go ahead and take out a few thing. And this is the simple process of creating an integer, having the value of that integer then reassigned to the return value from our add five function, and then doing the same thing again. So between Seattle and London, we should have one output that says we're adding five to zero, and then we should have another output that says we're adding five to five. And we can watch that value change dynamically as our Durable Function runs.
So let's go ahead and run that function and see what we get. Azure Functions, once again, displays our log, verifying we have a durable task running. And there's the endpoint that we're going to need to use, which of course, fortunately, turns out to be the same endpoint that we just used.
So now that we know that everything is up and running, we can actually just come back to our open browser, make another request to the same endpoint. When it's completely finished, we can go in, and we can take a look. And we can see that our function durable hello has been running properly, and so has our add function. here we can see down in the list, we're adding five plus five. Here further above, we're adding five plus zero.
So, as we are going through our Azure Function, and here's the beginning saying hello to Seattle, adding five plus zero, adding five plus five, and then at the end here, saying hello to London. And so, in this process, we have really been able to see very powerfully that Azure Functions can tie together in a number of ways, orchestrating your Azure Functions to create a sequence like this is one of the most powerful ways that you can manage your state and the logic within your larger application picture.
So, now we have successfully created an Azure Durable Function that has called individual activity functions. We have activated that function using an HTTP trigger endpoint. And that concludes the first part of our introduction to Durable Functions.
David Gaynes is a software and cloud architect for .NET, NodeJS, Azure and AWS. He has been developing .NET and Cloud software for more than 20 years, with some of that time spent at Microsoft, and has authored both technical and non-technical teaching materials as books and in other formats. He enjoys physics, meditation, and experiencing the natural wonders of Hawaii.