03. Azure using Python SDK: Develop and deploy your Azure Functions (http trigger)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we will cover how to create functions on Azure platform these functions are going to be serverless in nature and there are multiple functions to choose from so first we are going to get started with HTTP triggered function and we'll see like how to create it and deploy it on Azure platform when you have to create any Azure function then first of all actually we are going to develop the code locally and then we are going to deploy it from our local to Azure platform in this case the function is going to be HTTP triggered function which we are going to develop on our local machine and then from our local we are going to deploy it on Azure platform and before actually we deploy this function on Azure platform we need to have a function app created under Azure and inside that function app only we can deploy our functions and before actually we can get started with the development we need to install few extensions on our visual studio so you can either install Azure functions or you can go ahead with Azure tools so let's see how to install all these extensions so first we will go for Azure functions so you can come to your Visual Studio then you can click on extensions but then you can search for Azure functions you can find Azure functions over here and then you can see the details of visual functions over here at the bottom how does it work what exactly we need to do a second thing if you do not want to install Azure function that is also fine you can directly install this Azure tools and Azure tools will install so many things for you once you install is your tools it will support for Azure app Services as a static web app Azure functions as your storage as your databases everything so either you can install Azure tools or you can install Azure functions both will work for Azure function case once you have this function installed then you will see this Azure icon over here you can click on this Azure icon and then you can sign in if you're logging first time then you need to sign in over here once you do the sign in you will see your subscription in my case it's free dial so I am getting this free trial one and at the bottom you will see this workspace so this workspace is basically denoting the code which we are going to develop on our local machine and you can see the local icon over here so this workspace belongs to your local machine and then here we will see this function as your function this icon is for app service and static web apps all those things like if you install as your core tools then you will see all these icons if you have just stalled Azure function extension then you will see this icon so once we have this icon then using this icon only first of all we need to develop our code on our local machine so I'm just going to click on this and I am just going to click on click on create function and then you will see it will ask you a lot of questions over here so what I will do in this case so first of all actually you have to select a folder where your function is going to be created so I can browse and I can go to code I can create new folder and I can name it demo and I will select it all functionality files are going to be located into that demo folder only then I have to select language I will select Python and after that I do not want any virtual environment so I will skip it and after that it's seeing OK select a template so you can see we can create this serverless Azure functions for so many things you will have option for time trigger SVP trigger Cosmos event trigger event uh Q storage all these things as of now because we are just going to get started with Azure function so I will just select s2b trigger and then you have to provide a function name I can name it funk CTP and authorization level I will select function and I would like to open this widget I will open in current window only now we have this function file created so our code is going to be located in this init.py file so this is a very simple function you can see here it's just going to grab a name so we need to pass something in name and if the name is available then it will display this information so it will give hello and then whatever name you have passed then this distributed function executed successfully if it is not there then we'll say this is still executed successfully but pass a name in the query so this is a very simple function this is for demo purpose you can remove all this and you can put your logic also over here now next we have this function dot Json file and in this file you can see the script file it denotes what would be the entry point for your function and where your code is going to be located in what you can do like if you do not want to name your file like this then you can just create another file and you can write our code over there but you have to remember take that particular file and you have to update name over here also so that like that can be converted as an entry point for your function second paragraph what we have is related to bindings binding will let you know what kind of event will be triggered when the request is coming in or coming out better way to understand it like you can just take all this and go to your Bing and post it over there you can just ask is to explain it like what exactly each part is doing so binding is a way in which your function is going to interact with other data sources or Services the first level you can see auth level which is function because we have selected auth level as a function it means like if you want to trigger this function you can only trigger it using a function key and the type is going to basically to be triggered it means the function is going to be triggered by an HTTP request the direction is denoted is in this specifies that The Binding is for input data so when the request is coming in then these particular methods needs to be triggered and then the method is going to be getting pose so the function is going to responds to both get and post HTTP method at the bottom you see like another type of so the direction is out and name let's just check okay what does it mean so in the second binding in the array is HTTP output binding here the type is going to be http means The Binding is related to http this specifies that The Binding is for output data so in summary you can see this Azure function that is triggered by HTTP request and send an HTTP response so now we have this function created on our local machine so let's try to run on our local first so I will go to run and then I will click on run without debugging and you can see the task is going to get created here if you are getting this notification I can just cancel it and you can see I have got this particular URL so I will just you know click on this okay so now you can see we have got this response this s3p trigger function executed is successfully pass the name in the query string or in the request body for a personal response and this particular thing is coming from over here because we haven't passed any name so that's why we are getting you know this kind of information over here and what you need to notice okay when the function is going to get executed then we are also getting this information where it's executed this function so we're also getting like this kind of locks over here on Terminal as of now we are writing this code on our local machine so we need to make sure okay this is working fine on our local before we deploy it on Azure platform because whatever Behavior we are expecting over here similar kind of behavior we would be spending on Azure platform as well so let me try to see if I can pass any name over here as you can see I pass your name and when I pass a name it has executed the first line of the code where it's written okay this function executed successfully same information actually you will see over here also so now actually we can see our code is working fine right so what I can do I can just stop it I just press on Ctrl C to intervene it and then I can just press any key and it will close it out the next step is going to be to deploy this code on Azure to deploy this function on Azure platform first of all we have to create this function app so let's go to our visual studio and see how to create it now what exactly we need to do you need to log into your Azure account and it will give you your subscription so I am in free trial so it is giving that particular subscription to me after that I will just expand it and I will go to this function app here I will expand it so as you can see I don't have anything as of now so I will just click on this and here you will see an option creating function app in Azure so there are two options one is where users have to follow minimalist steps to create the function app and rest of the things will go in the default mode in advanced steps there are going to be multiple strips and each and every steps you can control it like based drawn your requirement so let me go to Advanced one and try to create it in the advanced mode here it's asking for globally unique name for your function app I will try to provide one function demo 3006 and yeah it has taken that name after that you have to select your runtime stack here I can select python 3.10 then you need to create a resource Group if you don't have any Resource Group created on your Azure platform then you can create it from here but if you have anything created over there then it will also list it out so I can see I already have this Resource Group created and I do not want to put it in the resource Group so I will just select this one after that it's asking for a hosting plan I will go with the consumption one and then I have to create a new storage account also so I don't have any storage account created so I will create over here and this storage account is required where this function is going to put its files so it needs to have a storage account also it is already giving me this name so I can probably just add storage into this and then this application inside resource is required to get the mattresses out of your function I will create this one also here it's giving function demo threes enter the name of so I will go with this one and now you can see it's trying to deploy this function on Azure platform so there are actually five steps that needs to be created and it's on step number two so let's wait for some time it's on step three now now it's creating that application inside a source so that is also fine and this is a fifth step okay so if everything goes well you can see this it got succeeded and you will also get this link from here so I will probably just copy it you can see your function has been deployed same thing got listed over here you can see this is a function app now let's check function app on Azure platform so I will go to my Azure platform and here I will try to search for function you can see this function app I will just click on this now you can see here we do have this function app created so first of all we are in function app under this function app like you can create multiple functions so I will just click on this function app so now our function app has been created now what exactly we need to do we need to deploy our function so I will just click on this icon and under this you can see deploy to function app I will click on this and it will show you the function app which we have recently created an under which resource Group we have created in so I will just select this and it's asking are you sure you want to deploy with just click on deploy and here you can see it's trying to deploy our local function on under this function app okay so here I can see the deployment to this function app is completed and you can also see over here we can see our local function got deployed under this function app same thing should be visible on Azure platform so we'll try to go over there and I will try to refresh it and I should be able to see something over here you can see this function is here it got deployed just click on this and here you can find the function keys so if anyone wants to consume this function outside or just want to call it because we have used the authentication mechanism as function so we need to pass this particular function key before calling this function this monitor tab we can use it to monitor the success and failure what we are getting when the function is being called here this is an integration one we can edit the functionality from here but rather than doing it from here we want to do it from our local and code and test also if you want to perform any kind of testing on your function you can also do it from particular portal from this UI and here you can see your functions over here like whatever code we have developed over there you can see you can verify whether you are able to see same function code over here or not and after that like if you want to test it out you can also test it from this particular UI but we will try to test it from outside and then the function call can be monitored from here now the next part is how to get this function URL what we can do for this we can go to this overview and after that you will see the Json view over here you can click on this and at the bottom you will see this invo URL template so this is giving me URL from Azure so the next thing is like how are we going to run this so first of all actually we will try to invoke it from here and then we will use the monitoring mechanism on Azure platform just to see whether this function is able to invoke or not earlier we were trying to run this method on a local only but now we will try to run it through our Visual Studio but it should be the mattresses and everything should be added on Azure plat I will just click on this and you can see execute function now so I will try to run it I will go with the name Azure the default one and you can see here it is saying hello this HTTP triggered function executed successfully what we can do in this case I just want to check whether anything has been captured over here or not we will try to make few calls and here you can see also the results may be delayed up to five minutes it can take some time before the information start getting reflected over here and if you don't pass a name so same thing what is expected from our code it will give you this particular message without mentioning any name so similar functionality what we were getting earlier so we have already made two calls as of now and we need to see whether we can monitor it via Azure platform or not again we need to wait for some time yeah so now you can see after waiting for some time we can see two success over here it means like it's able to capture the matrices so the first call is made at this time and it took like 56 millisecond if you click on this it will show you the lock here you can see the function was programmatically called by a host API we have got some additional information around it so this is how actually you can track the log of your function on Azure platform and you can see like two calls were success if there are any failure while calling this particular function or any function then you can show it over here so because our two calls are successful so that's why the count is two here okay so that's all for this video so here actually we have created our function on locally and then deployed on Azure platform in next video we will try to consume this function via Postman and Via code and we'll see like how to do it thank you for watching
Info
Channel: TechyTacos
Views: 960
Rating: undefined out of 5
Keywords:
Id: h8H4W4YwA0c
Channel Id: undefined
Length: 15min 20sec (920 seconds)
Published: Tue Oct 03 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.