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
€65.24
List Price:  €93.21
You save:  €27.96
£55.79
List Price:  £79.71
You save:  £23.91
CA$95.78
List Price:  CA$136.84
You save:  CA$41.05
A$107.15
List Price:  A$153.08
You save:  A$45.92
S$95.25
List Price:  S$136.08
You save:  S$40.82
HK$547.16
List Price:  HK$781.69
You save:  HK$234.53
CHF 63.78
List Price:  CHF 91.12
You save:  CHF 27.33
NOK kr771.03
List Price:  NOK kr1,101.52
You save:  NOK kr330.49
DKK kr486.66
List Price:  DKK kr695.26
You save:  DKK kr208.59
NZ$117.65
List Price:  NZ$168.07
You save:  NZ$50.42
د.إ257.05
List Price:  د.إ367.24
You save:  د.إ110.18
৳7,682.75
List Price:  ৳10,975.83
You save:  ৳3,293.07
₹5,839.27
List Price:  ₹8,342.17
You save:  ₹2,502.90
RM334.02
List Price:  RM477.20
You save:  RM143.17
₦92,745.84
List Price:  ₦132,499.74
You save:  ₦39,753.90
₨19,488.62
List Price:  ₨27,842.08
You save:  ₨8,353.45
฿2,593.98
List Price:  ฿3,705.84
You save:  ฿1,111.86
₺2,266.58
List Price:  ₺3,238.11
You save:  ₺971.53
B$358.23
List Price:  B$511.78
You save:  B$153.55
R1,308.04
List Price:  R1,868.72
You save:  R560.67
Лв127.69
List Price:  Лв182.42
You save:  Лв54.73
₩96,593.58
List Price:  ₩137,996.75
You save:  ₩41,403.16
₪262.11
List Price:  ₪374.46
You save:  ₪112.34
₱4,037.82
List Price:  ₱5,768.57
You save:  ₱1,730.74
¥10,982.62
List Price:  ¥15,690.13
You save:  ¥4,707.51
MX$1,188.90
List Price:  MX$1,698.50
You save:  MX$509.60
QR255.36
List Price:  QR364.82
You save:  QR109.45
P960.21
List Price:  P1,371.80
You save:  P411.58
KSh9,275.87
List Price:  KSh13,251.81
You save:  KSh3,975.94
E£3,354.25
List Price:  E£4,792
You save:  E£1,437.74
ብር4,018.25
List Price:  ብር5,740.61
You save:  ብር1,722.35
Kz58,443.04
List Price:  Kz83,493.64
You save:  Kz25,050.60
CLP$66,028.30
List Price:  CLP$94,330.18
You save:  CLP$28,301.88
CN¥506.69
List Price:  CN¥723.88
You save:  CN¥217.18
RD$4,095.54
List Price:  RD$5,851.02
You save:  RD$1,755.48
DA9,393.81
List Price:  DA13,420.31
You save:  DA4,026.49
FJ$158.42
List Price:  FJ$226.32
You save:  FJ$67.90
Q544.03
List Price:  Q777.22
You save:  Q233.19
GY$14,645.70
List Price:  GY$20,923.32
You save:  GY$6,277.62
ISK kr9,806.99
List Price:  ISK kr14,010.59
You save:  ISK kr4,203.60
DH708.51
List Price:  DH1,012.20
You save:  DH303.69
L1,235.26
List Price:  L1,764.74
You save:  L529.47
ден4,024.43
List Price:  ден5,749.43
You save:  ден1,725
MOP$564.37
List Price:  MOP$806.28
You save:  MOP$241.91
N$1,312.44
List Price:  N$1,875
You save:  N$562.55
C$2,589.99
List Price:  C$3,700.15
You save:  C$1,110.15
रु9,350.18
List Price:  रु13,357.97
You save:  रु4,007.79
S/262
List Price:  S/374.30
You save:  S/112.30
K266.57
List Price:  K380.83
You save:  K114.26
SAR262.49
List Price:  SAR375.01
You save:  SAR112.51
ZK1,865.62
List Price:  ZK2,665.29
You save:  ZK799.66
L324.62
List Price:  L463.77
You save:  L139.14
Kč1,642.25
List Price:  Kč2,346.17
You save:  Kč703.92
Ft25,489.50
List Price:  Ft36,415.13
You save:  Ft10,925.63
SEK kr767.15
List Price:  SEK kr1,095.98
You save:  SEK kr328.82
ARS$61,365.44
List Price:  ARS$87,668.68
You save:  ARS$26,303.23
Bs484.79
List Price:  Bs692.59
You save:  Bs207.79
COP$272,495.59
List Price:  COP$389,296.10
You save:  COP$116,800.51
₡35,128.88
List Price:  ₡50,186.26
You save:  ₡15,057.38
L1,728.92
List Price:  L2,470
You save:  L741.07
₲521,305.22
List Price:  ₲744,753.66
You save:  ₲223,448.44
$U2,682.06
List Price:  $U3,831.68
You save:  $U1,149.62
zł282.11
List Price:  zł403.03
You save:  zł120.92
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.