Lab 3: Azure Function Apps

Azure Step by Step Training Lab 3: Azure Function Apps
25 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€66.52
List Price:  €95.03
You save:  €28.51
£55.40
List Price:  £79.15
You save:  £23.74
CA$97.77
List Price:  CA$139.67
You save:  CA$41.90
A$107.48
List Price:  A$153.55
You save:  A$46.07
S$94.07
List Price:  S$134.39
You save:  S$40.32
HK$544.73
List Price:  HK$778.22
You save:  HK$233.49
CHF 61.85
List Price:  CHF 88.36
You save:  CHF 26.51
NOK kr773.61
List Price:  NOK kr1,105.21
You save:  NOK kr331.59
DKK kr496.19
List Price:  DKK kr708.87
You save:  DKK kr212.68
NZ$119.31
List Price:  NZ$170.45
You save:  NZ$51.14
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,370.95
List Price:  ৳11,959.01
You save:  ৳3,588.06
₹5,916.42
List Price:  ₹8,452.40
You save:  ₹2,535.97
RM312.50
List Price:  RM446.45
You save:  RM133.95
₦117,624.49
List Price:  ₦168,042.19
You save:  ₦50,417.70
₨19,473.08
List Price:  ₨27,819.88
You save:  ₨8,346.79
฿2,426.48
List Price:  ฿3,466.55
You save:  ฿1,040.07
₺2,418.28
List Price:  ₺3,454.83
You save:  ₺1,036.55
B$406.67
List Price:  B$580.99
You save:  B$174.31
R1,268.60
List Price:  R1,812.36
You save:  R543.76
Лв130.09
List Price:  Лв185.85
You save:  Лв55.76
₩98,070.61
List Price:  ₩140,106.88
You save:  ₩42,036.26
₪261.37
List Price:  ₪373.41
You save:  ₪112.03
₱4,133.88
List Price:  ₱5,905.80
You save:  ₱1,771.92
¥10,806.63
List Price:  ¥15,438.71
You save:  ¥4,632.07
MX$1,423.91
List Price:  MX$2,034.25
You save:  MX$610.33
QR255.44
List Price:  QR364.93
You save:  QR109.49
P956.94
List Price:  P1,367.12
You save:  P410.17
KSh9,046.20
List Price:  KSh12,923.70
You save:  KSh3,877.50
E£3,475.04
List Price:  E£4,964.56
You save:  E£1,489.51
ብር8,733.50
List Price:  ብር12,476.97
You save:  ብር3,743.46
Kz63,853.79
List Price:  Kz91,223.61
You save:  Kz27,369.81
CLP$68,157.66
List Price:  CLP$97,372.26
You save:  CLP$29,214.60
CN¥506.84
List Price:  CN¥724.09
You save:  CN¥217.25
RD$4,224.90
List Price:  RD$6,035.83
You save:  RD$1,810.93
DA9,349.94
List Price:  DA13,357.64
You save:  DA4,007.69
FJ$158.89
List Price:  FJ$226.99
You save:  FJ$68.10
Q540.76
List Price:  Q772.55
You save:  Q231.78
GY$14,655.30
List Price:  GY$20,937.04
You save:  GY$6,281.74
ISK kr9,679.61
List Price:  ISK kr13,828.61
You save:  ISK kr4,149
DH699.78
List Price:  DH999.72
You save:  DH299.94
L1,274.52
List Price:  L1,820.82
You save:  L546.30
ден4,093.48
List Price:  ден5,848.08
You save:  ден1,754.59
MOP$561.60
List Price:  MOP$802.33
You save:  MOP$240.72
N$1,270.52
List Price:  N$1,815.10
You save:  N$544.58
C$2,577.69
List Price:  C$3,682.57
You save:  C$1,104.88
रु9,455.06
List Price:  रु13,507.81
You save:  रु4,052.75
S/265.82
List Price:  S/379.77
You save:  S/113.94
K281.99
List Price:  K402.86
You save:  K120.87
SAR262.75
List Price:  SAR375.38
You save:  SAR112.62
ZK1,938.58
List Price:  ZK2,769.51
You save:  ZK830.93
L331.04
List Price:  L472.94
You save:  L141.89
Kč1,685.42
List Price:  Kč2,407.85
You save:  Kč722.43
Ft27,354.11
List Price:  Ft39,078.98
You save:  Ft11,724.86
SEK kr771.99
List Price:  SEK kr1,102.90
You save:  SEK kr330.90
ARS$70,181.20
List Price:  ARS$100,263.16
You save:  ARS$30,081.95
Bs485.08
List Price:  Bs693
You save:  Bs207.92
COP$308,906.07
List Price:  COP$441,313.30
You save:  COP$132,407.23
₡35,572.52
List Price:  ₡50,820.06
You save:  ₡15,247.54
L1,770.13
List Price:  L2,528.86
You save:  L758.73
₲548,589.81
List Price:  ₲783,733.33
You save:  ₲235,143.51
$U2,994.50
List Price:  $U4,278.05
You save:  $U1,283.54
zł289.22
List Price:  zł413.19
You save:  zł123.97
Already have an account? Log In

Transcript

So welcome to lab three. And in lab three, we will talk about something called as function apps. So this lab three is going to be approximately 25 minutes of video, and it's 35 minutes of video. First I will define, you know, what is function app, what is important of function apps, then we will see how to create function app using the as your portal. So there are various ways of creating function app. One is that you can create by using the as your portal, right, create function app using portal.

And second how to create function app using Visual Studio. Right. So again, we'll see how to create using Visual Studio. And also we'll talk about something called a scale controller, which actually helps you to scale up and scale down you know the resources which are used by function app. So this is going to be 25 minutes of video and in this unit, we are going to go and see these things. So let us start as you is a great cloud service.

And in this cloud service, you know, we can host big applications, like website, SQL databases. And when we host these big applications, we need to host them in a virtual machine, which actually costs us right. So when we host an SQL Server, if you remember, we had actually assigned a service plan and we need to provide a VM. If you remember, when we hosted web application in the first video, we needed a VM, right? So when we are hosting this big things, yes, we need a virtual machine. We can decide you know, what kind of virtual machine we want, depending on our load, and so on.

But now let's think about a scenario where I want to just host one function. I want to just host 10 lines of code. So when I host these kind of small functions, small routines, small code, right, I do need a virtual machine. I just want to be in the courtroom. So whenever the code runs, I just want to pay for whatever I have consumed. That's where you know, as your has provided something called as function apps.

So you can see at the left hand side there is something called as function apps. So you can think about functions apps are nothing but they are functions they are small code small routine, which can be hosted on a hosted on a car without a virtual machine. Now, whenever we whenever you host anything without a virtual machine, it is also termed as serverless. So function apps are nothing but small code, small logic, which get hosted on a car. And for that, we don't need to provide a big virtual machine, and we can host it in a serverless manners. So let us go ahead and create a function app.

And what we'll do is in this function in a we'll just go and display hello world. So let's start with small things. Let us not try to learn everything in one go. So in order to add a function app, So in order to add any resource, you know, if you're getting confused, you can always click on this plus sign. So let us click on this plus sign. And we want to go and add a compute thing.

Remember, if you want to add databases, here it is, if you do want to add web application, here it is. But when you talk about functions, when you talk about logic, they actually consume CPU a lot, right? So that's why I've clicked on Compute. And in this compute V, you can see that there is something called as function app. So let us click on function app. And let us give a name to this function app.

Now remember, whatever function you create, at the end of the day, they get hosted on cloud so you can see that they get this name like, my function.as, your website's dotnet or Hello world.as, your website's dotnet right? So I'm going to go and create your mind function 123 You can see my function 123 is also booked. So my function new. Okay, so my function new.as, your website's dotnet. On this URL, I'm going to go and host my logic. Okay, I'll be using this as you go, I will just go and create a new group.

But remember that it is always advisable to create a resource group and clump them into one resource group so that you can do accounting properly. And now in the hosting plan, you can see that it gives you two options. One is that if you wish, you can go the old way. For a simple function. If you think that your function will be consuming a lot of resources, you can go and create a service plan. And you can assign a full blown virtual machine to it.

Or else you can go with the consumption plan. In this consumption plan, what happens is, depending on the number of requests, which comes to that function, it actually assigns resources. So we'll come Do that. But at this moment, you can remember that in the consumption plan, depending on the calls made to that function, right? The function is allocated resources. So rather than using a full blown service plan, I will be using a consumption plan.

The location, I'll say, that is us for now. And now for a function, you need two things. One is that yes, it will consume your processor. But it also needs some storage, the source code needs to be stored somewhere, right? So we can see that I'm also creating a storage here. So I'll say my new function, storage, new function storage, right.

And there it is. So now I'll go and create this function here. And in this function, then we will go and write code. So we can see now I'm creating a function app with the name my function new.as, your website's dotnet. So there it is, you can see at the right hand side, it is deployment in progress. So after some time, you know the function will be deployed.

And it should be, it should be visible over here. You can also see now it's still getting deployed actually. Let's refresh so you can see that that my function is created. So I'll go to this function and inside this function now I want to go and create a function means this my function new is you know, in this I want to go and add a function a logic a code, so you can see that I've expanded the my function new and you can see that that is something called a plus sign here. I'll click on this thing here. Now, as we said that you know, this functions you know, function apps, you know, they are logic, but this logic can can only run you know, when some event happens, you know, when some trigger happens, so you can see it here it is saying that, okay, these are some pre made functions.

So when you host your function, how do you want to invoke it? Will there be some web API or a web hook, which will actually invoke the function, for example, will there be some kind of an HTTP request call, which will actually invoke the function. So in that case, you can take the first option. The second one is a timer, you know, wherein the function keeps running, you know, in a certain interval of time. And the third one is for data processing. So other two we'll see later on for now, let us go to the happy flow.

So I'm going to go and select on web hook plus API, which means that my function will be invoked via an HTTP request. Okay. And also, you can see that you can choose different languages here. If you say that you want to write this function in C sharp or you want to write using JavaScript, F sharp or Java. So you can see there are a lot of other languages also, which you can choose from. For now I'll choose C sharp, so I'm going to say create this function.

And once you say create, what it does is it actually creates You know, a file called last run dot CSS you can see over here, right. And in this you can see that he has put down some kind of C sharp code. Let me go and delete all of this, I know that it is so tough to understand. So let me make it simple. Let me see that, I want to send a response back. So I'm going to delete all of this.

So I'll say that this function will display just hello world. So what I want to do is, it is not a synchronous, it is a simple HTTP response message so you can see it I've just removed a lot of code from it, so that you can concentrate on the basic part of functions. So in this I will say that I want to return a response. So you can see here, this request is the object and using this request object. I'm creating a response and this response I'm saying hello world right world. And so I'll go and say save, I can either say save, or I can either say Save and Run.

So let me do a Save and Run. Now once I do a Save and Run, what it does is you can see that down below, there is a window in this window, it actually displays out here, if I do an expand, it displays out here log messages saying that your function is running properly, or if there is an error. So I can see that there are some errors. So I'm going to go and say copy logs. So that I can read this in a notepad. So let me paste it in a notepad here and let us try to read what it is what's written here.

It says invalid class token. Okay. So there is some other problem there. So, yeah, so we don't need this right. And I'll say Save and Run. And I'll clear all this log here, you know, just to check.

So now I can see that those arrows have gone from yours. So if I expand I can see everything is right. Now, as we said that this function actually gets hosted on as your on a URL, right. So you can see at the right hand side there is something called as an get function URL. So I'll just click on this, I'll copy this. So if I go now to my browser, I can go and run this.

So you can see now over here, that is displaying hello world. So you can see now my function is hosted in this, my function new.as, your website's. And in that it's hosted as an API. So you can see that this is the API slash HTTP trigger sharp one, this triggered C sharp one is nothing but this thing out here the name of the function. And you can see after that there is some kind of acorrea this code is nothing but a key. And this key is there for safety purpose to just check that it is not invoked by an anonymous user, right.

So that's a very simple example of creating a function app and hosting it in as your Now if you want to go and write complicated functions, functions, which have must be like, you know, 100 or 200 lines of code, then definitely not this kind of online editing won't work, right, you need IntelliSense you need to build it, you need to test it offline, and then upload it. So for that in, in Visual Studio, we can do that in case you are using C sharp as a language, you can definitely do it what you need to do is when you install your Visual Studio, you need to go and install the as your development workload. So you can see here when you actually go to you know, if you want to get the necessary support of hosting the as your functions, then you need to go and install this as your development kit.

Without this it is difficult. So once we install it, then you can go and you can create a project so you can see here is my Visual Studio, so I'll go and create a project. On so quickly. What I will also do is I don't want to waste money, remember I said, so what I'll do is I'll just go and delete all of these resources, just to ensure that I don't get unnecessary charges, right? Because we are learning as you're. So if you do something, once you are done with it, please do go ahead and delete it.

So you can see here. Yeah, some problem again, I can try to delete it. So let's delete it. Okay, so everything cleared, and I will not get unnecessary the necessary charges. So you can see here once I have installed the as your workload, then you get this cloud menu and in this cloud menu, you can see you can do a lot of as you're coding over here, but for now, our interest is this function, right? So let me go and create a function you're saying function, something my function 123 right.

Let us see okay. So in this now let us go ahead and add a new item. And let us go ahead and add a function class. So somewhere we should have as your functions that it is. So add this function one.cs. Now, this is very interesting screen, okay, the screen was also present in the online as your portal in that if you remember, you know we had selected we had those three ready made templates and in that we selected webhook and API, right.

So, this small this dialog box here says that this function is going to get triggered by what is there going to be some kind of an event. Will the data come from a queue? Is there a timer or is that an HTTP So, what I'll do is I'll select the most used one for now HTTP trigger And I will say at this moment, this can be called by anyone, so I'm going to just make it anonymous. If you select the function or the admin, then the necessity keys has to be passed or the necessary keys has to be sent you know, when you make the call. So for now, let let me make it anonymous, as we said, whenever you are learning something, first learn the happy path. Do not try to learn everything in one go.

Like at this moment, if I want, I can waste your one hour in teaching you each one of these things and you won't learn the basics right? So for now, let me go the happy path and then we will try to get into details. So I'll select HTTP trigger here. And then I will say anonymous, and I'll say okay, so there it is. Now, again, let me cut short all this thing, you know, it looks, there is a lot of async await. And those keywords out here if you know definitely you know, when you're calling an HTTP function, it has to be it has to have an async and await but phonology make it simple.

Let me just create a function one, which displays out a simple HTTP response message. And yes and in this I'm not interested at this moment to do any kind of log and so on. So I can remove this. So we can see now as compared to the online editor, this is definitely worth right. And what I'll do over here, I'm going to go and delete all of this. Okay, simple one, I just want to go in the response and say return Hello.

So hello, as your Hello from as your function apps functions. Okay. So you can see now this says anonymous and you can, you can call this via a get you can call this via a post, right? So, I will One builders that is first builders, sellers ensure that we don't have any problems. Now, one of the one of the, you know, good things about writing functions using as your functions using Visual Studio is that you can test it offline, you don't need to really go online and then run and then check right, you can just test it offline. And then you can go and host it online.

So there it is, you can see build started, everything is succeeded. I go and try to run this. So I'm going to go and try to run this. Now remember, whenever you try to run, by default, try to run this there is a possibility you can get one dialog box which says that please go and install the as your CLA tools as your function ci tools. The ci tools actually help you to run the web server, you know, they give you an URL, they create the environment you know, inside which are function apps can run. Okay, so you if you get this box, just say yes, wait for two, three minutes.

And it will install the as your ci tools. So you can see now my function is now running, you can see that as your ci tool is running, and you can see that my function is getting hosted in 7071 port. So there it is. So if I want I can go and call this function, so I will just say Ctrl C, and I can go and run this function from my local host. So, there it is, you can see I'm running this function and it is saying that Hello from as your functions right Great. So, everything is running over here.

If you want you can also go and put a debug point you can see here there is a debug point out here, if you do elevation and put a debug point, so if you hit enter, it will debug as well. So we can see now that is that it is debugging. And you can go and to add watch, you can go and do all the things right. So everything goes out here. It looks that everything is working. So now let us go and publish this.

So I'm going to go into publish this, I will say publish my function 123. So there it is, you can see that I have hit build, and then I've hit Publish. And he says that, okay, so you want to go and create a new as your function app? Or is that something you've already made? And inside that you want to put it. So I'll say I don't have anything existing, I'll create a new one.

So I'll click on this as your function app. And I'll say publish. Now, once I say publish, you know, you you know, you need to go and log in into an as your account for now, at this moment, this is my as your account out here responding to your questions, right. So I have I have selected that and you can see that it is saying, Now tell me what is your resource group? Tell me what is your plan? You know, and all that right.

So mostly, I can give a nice name here, function app. My new 123 right. And I will say publish Create. So, now what this create will do is it will actually go and do everything you know what we are done in the previous part of the video you know where we created the service plan when we created the name you know everything it will do it will also go and host this code onto as your So, you can see down below it is saying deploying step zero or four. So, let us give it a minute. So, you can see that the function has been deployed.

So, if I go now here and if I do a refresh, you can see that the function is now seen in the function apps and you can see this is function one year. Now, remember that this function has been hosted through Visual Studio it has been published through Visual Studio right. So, you cannot really see the source code you can see that it is actually pointing towards this DLL but yes, definitely you can go and run it So, you can we will go and get this function URL. We can see now because we have said that this is an anonymous function, it does not have the key at the back end means anybody can call it right. So I'll go and run this function and I should see the output. So there it is, you can see now it is showing your Hello from as your functions.

So definitely when you're talking about IntelliSense, you know, you're talking about proper source code you want in if your function is complicated, you want to debug offline, then, you know, using Visual Studio does make sense. So we have seen, like, how to go and create a function using the portal. And we have also seen how to go and create the function using Visual Studio. Also, I would like to comment on this hosting plan. Now, when you actually host your function apps, you know, sometimes you know you want to you want to just get charged for the time the function apps runs, you know, so you see that, okay, whenever the function app, app runs, and depending on how much time the function app runs, and depends On what it has consumed, you charge me. Right?

And the second thing you can be, you know, saying that no my function app is used left and right. So, I would like to create a full blown virtual machine. And I would like to put that function app inside that virtual machine hosted, right. So, this consumption plan is what is the first one you know, where in the function app will be charged, you know, depending on how much it runs. And in the second one, this app service plan is where you actually get a virtual machine and you will be charged for that virtual machine irrespective you know, you know, the function app runs or not runs. For example, now, let us say, I select this thing, you know, as one standard, so I will be charged this for 917.

INR irrespective my function app is running, or my function app is not running. But if I select the consumption plan in consumption consumption plan, I will be charged only for the time my function app runs Now, the next thing which comes to mind is that, so how does as your scale up and scale down. So what happens in a zip code is, you know, there is something called a sun scale controller. So this function app receives a lot of events, you know, it can receive an HTTP event, it can get bulk calls from Ms mq, it can have a timer event. So at the left hand side, there is an event. So this event is first sent to this to the scale controller, and the scale controller sees, oh, it's only a single request.

So he creates one function instance and serves your request, then it's possible it's, it's possible that it can get an MSM queue. Now, in MSM queue, you know, there can be 10 objects in a queue. So he will create 10 function instances. So the scale controller, you know, takes the responsibility of scaling up the number of function instances, or scaling down the number of function instances. And depending on that moment, you know, how much fun instance is created. And and what the function instance uses, you get charged.

So in case of consumption plan, there is a scale controller. But if you use a service plan, you have a virtual machine. So it all depends, you know how your workload is? If you think that your workload is not predictable, then I think it is good to use a consumption plan. But if you think that, yes, my workload is predictable, and it is huge in size, it's quite considerable in size, then must be you can use a service plan. So, so that was a small video on function apps now.

You know, so in the in this video, what we did is we talked about, you know, what is function apps, we created a simple function app by using the as your online portal, then we created by using Visual Studio, and we talked about something called as scale controller. Now definitely function apps needs more More dedicated time to understand, right because there are a lot of other things in function apps. But what I will do is for now, I will stop talking about function apps. We will also go through other menus out here. And then I will have one more dedicated session. Right?

So must be later on in lab seven or lab eight, right, I will have one more dedicated session where I will talk more in detail about function apps. So this was like an introductory video on function apps. Later on, you know, down the line, I will talk more in depth of function apps. Like we have various kinds of events in function apps, we have timer function apps, we have database function, abs and so on. Right, so we'll talk separately on that. So I hope that you enjoyed this video.

Now in the next video, we'll talk about something called as the as your Cosmos dB. Okay, so we'll talk about something called as an as your Cosmos dB. Thank you so much.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.