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
€67.10
List Price:  €95.86
You save:  €28.76
£55.67
List Price:  £79.54
You save:  £23.86
CA$100.49
List Price:  CA$143.56
You save:  CA$43.07
A$111.96
List Price:  A$159.95
You save:  A$47.99
S$94.87
List Price:  S$135.54
You save:  S$40.66
HK$544.16
List Price:  HK$777.41
You save:  HK$233.24
CHF 62.56
List Price:  CHF 89.37
You save:  CHF 26.81
NOK kr792.29
List Price:  NOK kr1,131.89
You save:  NOK kr339.60
DKK kr500.54
List Price:  DKK kr715.08
You save:  DKK kr214.54
NZ$123.74
List Price:  NZ$176.78
You save:  NZ$53.04
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,330.24
List Price:  ৳11,900.85
You save:  ৳3,570.61
₹5,945.56
List Price:  ₹8,494.03
You save:  ₹2,548.46
RM315.51
List Price:  RM450.75
You save:  RM135.24
₦108,149.19
List Price:  ₦154,505.46
You save:  ₦46,356.27
₨19,403.53
List Price:  ₨27,720.51
You save:  ₨8,316.98
฿2,393.75
List Price:  ฿3,419.79
You save:  ฿1,026.04
₺2,454.67
List Price:  ₺3,506.82
You save:  ₺1,052.15
B$425.95
List Price:  B$608.53
You save:  B$182.58
R1,282.09
List Price:  R1,831.63
You save:  R549.54
Лв131.15
List Price:  Лв187.37
You save:  Лв56.21
₩101,234.93
List Price:  ₩144,627.53
You save:  ₩43,392.60
₪254.67
List Price:  ₪363.83
You save:  ₪109.16
₱4,117.86
List Price:  ₱5,882.91
You save:  ₱1,765.05
¥10,949.58
List Price:  ¥15,642.93
You save:  ¥4,693.35
MX$1,405.49
List Price:  MX$2,007.92
You save:  MX$602.43
QR254.12
List Price:  QR363.05
You save:  QR108.92
P963.49
List Price:  P1,376.48
You save:  P412.98
KSh8,999.72
List Price:  KSh12,857.29
You save:  KSh3,857.57
E£3,561.31
List Price:  E£5,087.81
You save:  E£1,526.49
ብር8,689.79
List Price:  ብር12,414.52
You save:  ብር3,724.72
Kz64,250.82
List Price:  Kz91,790.82
You save:  Kz27,540
CLP$69,143.42
List Price:  CLP$98,780.55
You save:  CLP$29,637.13
CN¥510.67
List Price:  CN¥729.56
You save:  CN¥218.89
RD$4,244.94
List Price:  RD$6,064.47
You save:  RD$1,819.52
DA9,440.04
List Price:  DA13,486.35
You save:  DA4,046.31
FJ$162.13
List Price:  FJ$231.62
You save:  FJ$69.49
Q537.12
List Price:  Q767.35
You save:  Q230.22
GY$14,584.29
List Price:  GY$20,835.60
You save:  GY$6,251.30
ISK kr9,693.35
List Price:  ISK kr13,848.23
You save:  ISK kr4,154.88
DH701.59
List Price:  DH1,002.31
You save:  DH300.72
L1,285.64
List Price:  L1,836.70
You save:  L551.06
ден4,127.89
List Price:  ден5,897.23
You save:  ден1,769.34
MOP$558.06
List Price:  MOP$797.27
You save:  MOP$239.20
N$1,283.39
List Price:  N$1,833.49
You save:  N$550.10
C$2,565.21
List Price:  C$3,664.75
You save:  C$1,099.53
रु9,482.30
List Price:  रु13,546.73
You save:  रु4,064.42
S/259.58
List Price:  S/370.84
You save:  S/111.26
K282.68
List Price:  K403.85
You save:  K121.16
SAR262.90
List Price:  SAR375.59
You save:  SAR112.68
ZK1,929.21
List Price:  ZK2,756.13
You save:  ZK826.92
L333.95
List Price:  L477.10
You save:  L143.14
Kč1,686.22
List Price:  Kč2,408.98
You save:  Kč722.76
Ft27,781.83
List Price:  Ft39,690.03
You save:  Ft11,908.20
SEK kr772.17
List Price:  SEK kr1,103.14
You save:  SEK kr330.97
ARS$71,242.69
List Price:  ARS$101,779.64
You save:  ARS$30,536.94
Bs481.71
List Price:  Bs688.19
You save:  Bs206.47
COP$305,135.87
List Price:  COP$435,927.07
You save:  COP$130,791.20
₡35,171.10
List Price:  ₡50,246.58
You save:  ₡15,075.48
L1,769.55
List Price:  L2,528.04
You save:  L758.48
₲543,563.42
List Price:  ₲776,552.46
You save:  ₲232,989.03
$U3,109.25
List Price:  $U4,441.97
You save:  $U1,332.72
zł286.15
List Price:  zł408.81
You save:  zł122.65
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.