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
€64.93
List Price:  €92.76
You save:  €27.83
£53.99
List Price:  £77.13
You save:  £23.14
CA$97.22
List Price:  CA$138.90
You save:  CA$41.67
A$105.43
List Price:  A$150.62
You save:  A$45.19
S$92.47
List Price:  S$132.11
You save:  S$39.63
HK$544.12
List Price:  HK$777.35
You save:  HK$233.22
CHF 60.91
List Price:  CHF 87.02
You save:  CHF 26.11
NOK kr763.93
List Price:  NOK kr1,091.38
You save:  NOK kr327.44
DKK kr484.20
List Price:  DKK kr691.75
You save:  DKK kr207.54
NZ$116.54
List Price:  NZ$166.49
You save:  NZ$49.95
د.إ257.07
List Price:  د.إ367.25
You save:  د.إ110.18
৳8,342.01
List Price:  ৳11,917.67
You save:  ৳3,575.65
₹5,905.60
List Price:  ₹8,436.93
You save:  ₹2,531.33
RM306.80
List Price:  RM438.30
You save:  RM131.50
₦117,690.28
List Price:  ₦168,136.18
You save:  ₦50,445.90
₨19,401.12
List Price:  ₨27,717.08
You save:  ₨8,315.95
฿2,383.57
List Price:  ฿3,405.25
You save:  ฿1,021.68
₺2,404.89
List Price:  ₺3,435.70
You save:  ₺1,030.81
B$398.48
List Price:  B$569.28
You save:  B$170.80
R1,224.40
List Price:  R1,749.21
You save:  R524.81
Лв126.98
List Price:  Лв181.41
You save:  Лв54.43
₩97,065.96
List Price:  ₩138,671.61
You save:  ₩41,605.64
₪260.93
List Price:  ₪372.77
You save:  ₪111.84
₱4,079.82
List Price:  ₱5,828.56
You save:  ₱1,748.74
¥10,651.14
List Price:  ¥15,216.57
You save:  ¥4,565.43
MX$1,389.48
List Price:  MX$1,985.06
You save:  MX$595.57
QR254.42
List Price:  QR363.48
You save:  QR109.05
P932.03
List Price:  P1,331.53
You save:  P399.50
KSh9,028.71
List Price:  KSh12,898.71
You save:  KSh3,870
E£3,450.40
List Price:  E£4,929.36
You save:  E£1,478.95
ብር8,593.22
List Price:  ብር12,276.56
You save:  ብር3,683.33
Kz63,785.40
List Price:  Kz91,125.91
You save:  Kz27,340.50
CLP$67,067.21
List Price:  CLP$95,814.41
You save:  CLP$28,747.20
CN¥501.07
List Price:  CN¥715.84
You save:  CN¥214.77
RD$4,196.59
List Price:  RD$5,995.39
You save:  RD$1,798.79
DA9,345.90
List Price:  DA13,351.85
You save:  DA4,005.95
FJ$158.38
List Price:  FJ$226.27
You save:  FJ$67.89
Q539.99
List Price:  Q771.44
You save:  Q231.45
GY$14,604.65
List Price:  GY$20,864.69
You save:  GY$6,260.03
ISK kr9,655.82
List Price:  ISK kr13,794.62
You save:  ISK kr4,138.80
DH690.36
List Price:  DH986.28
You save:  DH295.91
L1,255.31
List Price:  L1,793.39
You save:  L538.07
ден3,995.33
List Price:  ден5,707.86
You save:  ден1,712.53
MOP$560.14
List Price:  MOP$800.23
You save:  MOP$240.09
N$1,220.30
List Price:  N$1,743.36
You save:  N$523.06
C$2,568.69
List Price:  C$3,669.72
You save:  C$1,101.02
रु9,424.24
List Price:  रु13,463.77
You save:  रु4,039.53
S/263.85
List Price:  S/376.95
You save:  S/113.09
K280.16
List Price:  K400.24
You save:  K120.08
SAR262.89
List Price:  SAR375.57
You save:  SAR112.68
ZK1,891.77
List Price:  ZK2,702.65
You save:  ZK810.87
L323.06
List Price:  L461.54
You save:  L138.47
Kč1,638.32
List Price:  Kč2,340.56
You save:  Kč702.23
Ft26,373.60
List Price:  Ft37,678.19
You save:  Ft11,304.58
SEK kr750.79
List Price:  SEK kr1,072.60
You save:  SEK kr321.81
ARS$69,550.94
List Price:  ARS$99,362.75
You save:  ARS$29,811.80
Bs484.09
List Price:  Bs691.59
You save:  Bs207.49
COP$308,434.77
List Price:  COP$440,639.99
You save:  COP$132,205.21
₡35,749.40
List Price:  ₡51,072.77
You save:  ₡15,323.36
L1,761.10
List Price:  L2,515.97
You save:  L754.86
₲541,831.22
List Price:  ₲774,077.78
You save:  ₲232,246.56
$U2,924.58
List Price:  $U4,178.15
You save:  $U1,253.57
zł280.93
List Price:  zł401.35
You save:  zł120.41
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.