From the course: Azure Serverless Computing

Functions Overview - Azure Tutorial

From the course: Azure Serverless Computing

Start my 1-month free trial

Functions Overview

- [Instructor] When we talk about Azure, kind of in general, when it first released, it was a Platform as a Service. They offered out cloud services, and in a cloud service, I go out and define my frontend and my backend. I'd have web roles and worker roles, and there's a lot of infrastructure that went with that, a lot of code, a lot of pieces to make that all happen. And it's kind of clunky, you have a startup where the role would start up and spin up and it would take 10 minutes for a machine to get going. And it worked 'cause I could spin up a machine, I could spin up 100 machines, I could spin up 1,000 machines in 10 minutes, but being able to separate out that frontend and backend and make it more responsive, Azure has really kind of evolved since then to have application services where I can go out and build just a web application and kind of like a hosting farm, if you will, of compute services and offer that out to get people so they can just go out, build their application, and run it with just updating the website. But that backend work was still something that needed to be done, and so, along with application services, they included WebJobs. WebJobs was like a worker role, except you didn't have to have the entire startup of an entire machine. You could just spin it up and it would go out and you would run the WebJob as you need to. The nice thing about WebJobs is they're triggered by different things. They were triggered by Blobs, so if something got put into a Blob storage, it would open up, take the whatever, like an image being uploaded, create a thumbnail, or you could have jobs that would do processing, taking data and maybe reformatting it, moving it from place to place. And the WebJobs really were part of that application service in the sense that it did the background processing. And it evolved from that into what is now called Functions, and Functions is just offering just that part of the backend, but also extending it so you can do more with it. So, Azure Functions really give us the ability to go out and create a trigger-driven, nanoservice, pay-as-you-go kind of a model where I can focus just on the code, be able to go out and create the logic that will do whatever kind of processing I need. The serverless name came along because I wasn't creating a web application or any other infrastructure around it, I was just creating a Function and then just running it when something happened. In our scenario where we're building out our weather alert system, we're gonna use the Functions to take our data that has come out that are alerts and be able to put them into something so that we can process them later on to send out an email. And to do that, we're looking at working with the tools and the platform to go out and build this. Now, inside of the Function environment, I don't have to have a Visual Studio or whatever, I can just create the Function script inside the portal and run it, although I do have the opportunity to use the tools inside Visual Studio to give me an even better experience. The serverless design is a distributed architecture. It supports the asynchronous kind of processing. It allows us to scale up very quickly, very, very, very quickly by using a consumption model or we can have our own dedicated hosting plan if we want, but it allows us to go out and create Functions that will run when things happen. So, for instance, if I've got millions of messages coming through on the Event Hub, I can trigger a Function to run on every one of those and Azure will support that. So, some of the common scenarios you'll see Functions used for include things like going out and simulating a data ingestion system. What we're building with the Raspberry Pi simulator, we could've done with a Function and have that talking to the IoT hub. We could use a timer to be able to do that and have this run every second or every five seconds, be able to go out and create a burst of messages. We could also use this to handle processing data for a mobile backend where maybe I want to have a place where I upload a picture and have the backend then take that picture, create a thumbnail, and then work along. You can also use it for processing stream data, you can use it for triggering on keywords. Use it for going out and maybe identifying something like a cognitive services where you wanna run a logic against some kind of set of data. Maybe I wanna run an experiment and then score it for machine learning. I could trigger that from a Function. When you go to the portal and you start working with the Azure Functions, you've got a number of different templates that are available. So, right from the get-go, I can go out into the portal and create a Function inside the portal with a script that is gonna be triggered by something and then does some sort of binding to inputs and outputs. There are a number of different things I can trigger my Function app off of. I can trigger off the existence of a Blob or an Event Hub event happening. I can create webhooks so that I can have a web application might go out and trigger my Function and it goes off and does whatever the logic is. Like, for instance, I might want to have a event registration system, and so when you go out and create a registration, I could have a Function that sends a follow-up email. And then I could have a end-of-day kind of a Function that runs on a timer to go out and say, well, how many people do we get and create a report that then we could run later on. We can trigger off of the queues, Service Bus, timers. You also have other kinds of triggers that are out there as well. The types of Functions, like for a timer, you create a CRON expression where you specify how often you wanna run the job. You can send information into systems, but you don't necessarily get data back. It's usually used for kind of a background kind of a routine process, a batch type of a process. You can do data processing Functions that are good when you have an insert, update, or delete and you wanna be able to respond to that data going through the system. You can also have Functions that are gonna be looking at where something happens in another application and you want to maybe do a workflow, like maybe send off an email or mimic an API. The Functions can have multiple inputs and multiple outputs, but it can have only one trigger, and based on the type of the Function and the type of service, the bindings that are very simple to work with and use inside of our application. And we're gonna show how we can do that. When it comes to writing the Functions, what language is your favorite? Are you a C Sharp programmer? Do you like JavaScript? You can also do Python, PHP, and there are other experimental languages that they're creating as well because what it's doing is it's creating a scripted version of that and then executing it when I call it. So, let's take a look at how we can actually do this in the portal.

Contents