Create & Deploy Serverless Dot Net Core Web API with Lambda Fucntion & API Gateway

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to this session today we are going to see how to clear the server less web api in asp.net core using lambda function and we are going to call it to an api gateway so before jumping into the hands-on let me brief you about the technologies which you are going to use asp.net core it is a lighter version of asp.net but an open source and a better performing by framework it is developed by Microsoft and its community so you can get all the support from the community blocks AWS lambda function it is a server less compute service that runs your code without provisioning or managing the servers it is like you just upload the code and forget about it lambda function will take care of its scaling resource allocation and even performance and the best thing is you will be charged only for the compute time so this is the architecture which we are going to achieve in this video we are going to hit an HTTP request to an API gateway which will internally call the AWS lambda function and it will invoke the dotnet code API so the prerequisite will be you have to download the dotnet core SDK 3.1 which is the latest as of today and we are going to use the Visual Studio code as an IDE to develop this API and we also need an AWS account to interact with the lambda and API gateway before we start with the coding make sure after installing all the software's you should restart the system so let's start with it I have already opened the Visual Studio code let me create a new terminal to confirm whether the SDK has been successfully installed I am going to just check the version of it so we can see 3.1.3 has successfully installed now to create a dotnet core web api with the lambda function we have to install some some of the templates from the Amazon so I'm gonna install the.net new install amazon.com rIDOT templates so here we go it is successfully installed and I have got all the lambda packages as you can see we are gonna use this server less asp.net Web API template from lambda and we are going to create a new project with that so dotnet new server is dot asp net core of api and i'm gonna name it as values api it has been successfully created let me go and open the project folder so as soon as you open this Visual Studio will give a pop-up download the dependencies go ahead and download it you can also download the dependency by going inside the source folder and giving a restore command so I'm gonna go inside the source e-value CPA and I'm gonna give a command dotnet restor this will also download all the dependencies and rest over my project similarly I will go inside that test folder and keep the same dotnet restore command so now you can see both the project has been restored so there are two folders which God created the SRC folder is the actual project folder and this test folder is the step suit for this particular project so there are two entry points one is local and one is lambda 1.is to debug it in local or run it in local and one is for the lambda execution both will point to the startup class and which will internally point to the controller class and also you can see a serval as template which has all the configuration which is required to run this API in the lambda here we can also see the configuration related to s3 buckets which we are not going to use so I'm gonna delete this off you have to delete all the configuration which has bucket on it and also we are not going to need the API endpoint if we will be configuring it manually in the API gateway so the server last template is ready here we can also see that there is a controller method for the s3 bucket which we are not gonna use that so I'm going to delete this so let's see what is there in the value controller so this is a default API or get method with API values as a resource and that will return a value 1 and value 2 as a string we can also see there is a there is another great method in which if we will pass the value it will return a value string let's go ahead and run the API and see what we are getting running and that works pretty well so my API is running on localhost v w1 which is a default port for dotnet core API so let me see the controller value which is a get method and I'm gonna paste this over here and see if I'm getting the yes I am getting the values let me change this to my name and see if I'm getting the value oh I have to rerun the program yep it is working fine and oh and what about the other API where I can pass the value and I can get this value instead of that I can return my name let me refresh it again and oops and that is also working absolutely fine so let's go ahead and build the application and deploy it in lambda function and let's connect it through the API get where and try to call it if it works the same way we are good to go so to build the application first let's stop this and let's go to a new terminal go inside the source file and the values API and do a dotnet build build is successful let's publish the build dotnet publish in their release mode so the file has been published let me go to the bin folder and search for the published file so here it is let me go and sip it up so that I can upload it at one shot in the lambda API so now we just have to open our AWS account upload this zip folder into the lambda function and connect it to the API gateway and call it let's do that so I am in my AWS management console let me go to the lambda management console here we can go and create a function I'm going to name it as values API and the runtime environment is taught net code 2.1 here you can either choose your existing role or you can go ahead and create in your new role anytime you want I'm gonna select my existing role and go ahead and create a function so the lambda function has been successfully created and a link to that has already been generated this link will be helpful to connect this lambda to the API gateway let me go and upload the published file here it is and this is important this handler you can get it in our project server this template handler just copy and replace this and save it a lambda function has been created pretty easier so let me go to the API gateway I'm gonna create a new API a RESTful API we'll walk here and the name will be yeah values API leave the rest as it is so the API has been created we just have to give the resources so in our controller the resources is API and values and it is a get method let's go ahead and create a resource called API and then I'm gonna create another resource values so let's create a method which is a get in this case and I'm gonna check this proxy in English integration which will help me to connect to my lambda API I'm gonna paste the same air and which I have copied from my lambda function and I'll click on save so the API gateway is successfully connected to my lambda function that's just it API values this is correct let me go ahead and test it and it is giving me a correct values okay let's publish this API I'm gonna select a new stage and stage name as prod so it has been published to get the link of this you have to click on this get and this is the link of the API so if I will call this in the browser you can get the expected result so we have connected the API gate where do the lambda function and do the dotnet core Web API this is a very small example on how we can achieve this architecture it is pretty easy and it is a lot more cost-effective compared to the ec2 instances in AWS so thank you for watching this video if you do like the video please hit the thumbs up button and do not forget to subscribe to my channel so that you will not miss any of my video going forward I'll be back next time with some new technologies some new concept and some new architecture until then see you next time
Info
Channel: NextGlogy
Views: 9,324
Rating: undefined out of 5
Keywords: AWS, Dot Net, Lambda Function, API Gateway, Web API, .Net, Learn New Technologies, Next Gen Tech, NextGlogy, WebAPI, Dot Net Core, Dot Net Core 3.1
Id: HVW-g-5w_gg
Channel Id: undefined
Length: 14min 40sec (880 seconds)
Published: Sat Jun 06 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.