Visual Studio Code C# AWS Lambda | Serverless Cloud Computing

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi and welcome to coding is for you today we're gonna do something very interesting if you don't know it Amazon Web Services the next biggest hottest thing the reason it's so big is because they have so many services now that take away the burden of handling computers and networking and all that stuff they take them away from you and companies so what you do is you rent compute space as you need it you don't need a room full of servers anymore with a guy paying a guy just to sit there and maintain them and buy hard drives and backups and all that that's why it's so cool because you can actually save money in the long run by not having to pay people to maintain computers and all that stuff okay so Amazon Web Services is the cloud all that means is that they you can host a lot of your backups and your files and your computers and all on their services somewhere else that's all that means what we're gonna look at today is one specific service of many they have many many services but one of them is called lambda lambda is it's almost like just a little bit of code that you can run without having a full server that's why they call it server list so a server is a computer usually that you have with windows and it's got all kinds of in software and patches and stuff and then you need to have that server to run some code with lambda you don't need all that stuff all you need is just one little service that you can set up and then you can put some code on it and run it and so this is a very narrow view of what we're gonna do today but that's what we're gonna do so let's get started okay first of all you need to know that lambda is actually behind the scenes it's running Linux that's why you can't open up visual studio Microsoft Visual Studio create a program and just push it out there and expect it to run that's why we're using Visual Studio code because it uses dotnet core which is cross-platform that's why we're using dotnet core it's very important concept dotnet core allows you to do c-sharp which is what we're gonna do today and run it in lambda or on Linux or in any platform that's what's so cool about as long as you have done that core you can run it on other platforms so the first thing you need to do let's install go-to dotnet core SDK type that in and you need to have this installed go ahead and install in my case dotnet cord 2.2 download the SDK install it okay I'm not gonna go through that you just have to do it the next thing you need assuming you don't really have it is Visual Studio code and we're gonna download that and I'm also not gonna go through that I happen to be running Windows but you don't have to that's what's so cool about it download your version in have Visual Studio code installed the next thing you need is an account on Amazon Web Services now what they do is they give you this free tier for like a year where you not to pay anything as long as you keep the services very minimum and that's what we'll do anytime you create a service on Amazon Web Services be sure and just delete it right afterwards that way you don't accrue any cost and that's not hard to do I'll show you how to do that but go ahead and create account sign up giving me a credit card don't worry it's not a big deal you can always cancel it if you want but you have to have an account to complete this task because we are using their services and they do require a credit card to use their services which makes sense okay so I'm in the AWS management console and this is where we're going to build everything so the way we're gonna do that there's many different ways but the way we're gonna do this is we're going to build a project in Visual Studio code we're gonna take the code and we're gonna push it up to Amazon Web Services in lambda and then run it test it and run it in a couple different ways alright so first of all let's open Visual Studio code now before we go any further I will tell you that I got a lot of my information from also of course from the web I will provide a link to what you can see here and I recommend you click on the link link and read it it will be in the description read through this it gives you the commands that you need I'm just gonna show you the important ones so we have Visual Studio code open and we want to go down here to our extensions and we're gonna put in type in c-sharp and let's get this one called powered by Omni sharp let's get this installed go ahead and click install and let that install and this will help us out as an extension there's tons and tons of extensions that's what's really cool about Visual Studio code so if you I had to close Visual Studio code down and open it again but if you go here you can see that you have it installed that's gonna help us out a little bit okay so the next thing we want to do I like to keep everything nice and clean but let's create a folder from which we can work and I'm gonna do that right here in an attempt I'm gonna create a folder called AWS okay good enough now we have a folder called AWS I should have left that open let's open that folder and everything that you did should show up right here in this folder so it's totally empty right now we see that I hate this little welcome screen it annoys me alright so your folders are up here at top your debug is right here and your extensions are right there but we're handing the folders and we have nothing in it and that's okay so what we're gonna do now is we're gonna install some templates this is very important part so let's hit ctrl + tilde which is the next to the one control tilde and you can kind of see it somewhere in here what we need is the terminal so you also go here control new terminal and your terminal is gonna be your best friend okay so you're gonna install a lot of things here if you go through here and I'm doing it for you if you look at this command right here we can copy it and we can paste it in visual studio code in it what it's doing is it's installing the Amazon lambda templates that we are going to use and steal from once you have a template you can create it and it will just create the project for you and it does so much for you okay and that's what it's gonna get us up and started so run this command dotnet new - I amazon that lambda templates : : star we run that now notice it shows you all the templates that are now installed and look at this we've got all these lambda templates see all those what we want to do is what we're going to be doing is using this very simple lambda empty function later on when you want to connect to lambda s 3 s 3 is Amazon Web see all of these are tools on AWS that you need to learn but lambda s3 I believe is like a it's like a folder you can deal you can move files to and from Amazon Web Services and using these lambda functions in using lambda s3 but what we're doing we're not doing any of that we're just doing lambda empty functions so the next command I'm gonna type clear I like to type clear and clear everything out so now if you wanted to take this command dotnet new - all dot net new - all you can see all the templates that are installed and we just did the lambda once but whenever you do a dotnet new as you've seen before you can pick some of these different project types and we'll create templates for you that's what it's for so let's do our template okay so now we're going to use the template and the way we do that is we're gonna steal this line right here we're gonna change it a little bit let's copy that paste it now what we want to do is we're gonna use that template and we're gonna do a dotnet new lambda empty function we're gonna give it a name and it's gonna go on that folder right there the AWS folder but let's give it something that's a little bit better and simpler my proj project okay and then we don't need a profile right now we'll look at this line we're gonna put it into a region we're telling it what region we're going to and what that is as Amazon has all these different regions up here and what it is is they spread out all their computing across the world that way if something goes down you can use another server somewhere else like if there's a major fire in Virginia and that whole thing goes down you can use Ohio and if that goes down you can use California so it's this distributed idea and you have to tell it usually we're gonna stick in US East North Virginia and that happens to be us East one so what that will do for us is later it'll create a settings so we're gonna do this dotnet new lambda empty function we're giving it a name we're gonna hit enter now look what it did it created a new project now actually created two projects the first one is the source project that's what we're gonna be dealing with I'm not gonna worry about tests right now will you do that later in the future tests are just ways to run and test your your code but we'll just totally ignore that for now okay so now what we want to do is we need to build this code we need to make sure it builds and runs let's open up the function that we are actually coding in and look we've got c-sharp let me get rid of all the comments and garbage that we do not need now remember this template built all of this for us notice how it's saying oh wait I don't know what any of this stuff is and down here on the bottom right it says there are unresolved dependencies please execute the restore command to continue I'm gonna go ahead and just click restore and let it do its thing and it's going to install all the dependencies that it's a it knows that we have dependencies and so it's going to install them for us and look it's doing the work for us if you wait long enough you have eaten you have patience it will fix it so now look all of our dependencies have been resolved now let's go back to the terminal let's clear it out let's go let's run a command we're gonna do a restore manually on our own and the way you do that is notice we're on seed temp AWS that's kind of a problem because AWS folder is way up here we need to be way down here where a project file is and to do that we're gonna do a dir that's a directory listing and notice the next folder underneath is my project so I'm gonna do it change directory into my tab project hit enter now we're gonna do a dir again now remember we have a source project and a test project so we want to go into the source CD SRC dir again CD my project tab tab if you start to type in you hit tab it will bring it up clear I'm gonna clear it out dir okay now we are actually this whole path is in the same directory as your project file that's very important otherwise you will not be able to do this dot net restore a.net restore will kind of do a dependency check and make sure that all your links and dependencies are there now we're gonna do a dot net build and we're building so that means everything worse but course it's an empty template so now let's take a look at the code so it gave us a single function over here and all it does ignore all this stuff up here you know it's just those are just helpers we have a namespace called my project in a class called function and we have a function handler it takes in a single string and it returns an input dot to upper so whatever you type in like Hello lower case it'll take everything in return in an upper case so we're putting something in and getting something back which is a string all of that is good and fine let's clear this out now let's finish up and compile this code into one single unit and push it up to Amazon Web Services so we can use it in lambda all right so we're gonna do dotnet publish so what's that's doing is it's building and it's also creating one single folder with everything you need let's take a look at our folder so our folder is deep down here I have under seed to AWS my project source my project again bin-debug net core app 2.1 publish alright my publish created this publish directory deep inside the code in all these files right here what we need to push out to Amazon Web Services so we can use lambda it needs all of these compiled files to run what we just did now notice that it's under this net core app 2.1 if you have problems with your SDK in your your version you need to look in the project file and make sure that all your versions work so look at this net core app 2.1 and we are using we installed at sdk we have net court 2.1 so we're gonna take all these files right here we actually don't need them all but we'll do it anyway we're gonna take them all and we're gonna put it into a zip file and the reason why is because amazon likes for c-sharp it likes zip files so we're gonna right click we're gonna send to compressed zip folder my and my name it files my files dot z IP ok now you have your amazon web service you have your Amazon Web Services console you're gonna type in lambda and notice I have shortcuts up here I've got API gateway that's that's a way to create an API so you can call it from over the Internet I've got s3 that's buckets as folders I've got cloud formation these are all different tools but we're using lambda you're gonna type in lambda here and find the service and there it is right there lambda okay I've already created a function already I'm gonna delete it I'm gonna click there I'm gonna go delete that way we all start fresh okay now back to lambda you should see something like this now we are in that I'm just gonna stay in this one reason region US east one I'm gonna go to create function I'm gonna go down here and say notice that you can do all different types of languages you can do Ruby Python Java we did dotnet core 2.1 that's what we're doing so I'm gonna click on that and we're gonna tell it I'm gonna call it my function now it's gone it wants to have a role so the first time you do this you might might need to create a new role and just create a role and give it a name I already have a role so I'm going to create cheese an existing and then I'm gonna pick it I'm gonna call it service role my role just create a blank role and don't worry about it and click on it and then select it and we're gonna create function down here like this okay so we have my function and don't worry about all this other stuff going on it's it's advanced stuff we're gonna go down here to the code and guess what we called it a c-sharp app and so if you were to have chosen node for example you could type in your code right here you could type your code in right here but we didn't we did c-sharp 2.1 right there we're gonna upload a zip file that same file that we just compressed that we that we compiled we're gonna upload it here I gotta go to C temp AWS my project source my project bin debug net core app publish and then there are my files that I zipped up there actually all these other files click on it and don't worry about all this other stuff we're gonna hit we already did upload now the other important point is this right here you have to tell AWS lambda which function that you're firing off now let's go back and look click on the info right here and it's giving you a sample but this isn't right we need to click on info and it tells you what the way you do this it has to have a four parts to the name you have to have the assembly the namespace the class name and the method name so what that means is the assembly is the dol that you created my project let's go ahead and put that in right now my project that's the assembly the next one is namespace go to your code what's the namespace it's right here my project this is what we built class name what's the class name it's right here function and then the actual name of the function and then the actual name of the function which is function handler copy/paste so we have my projects assembly then we have the namespace we have the name of the class it's not a good class name by the way function is not a good class it's confusing and then function handler is the name of the function we're gonna hit save now your function should work as it is so let's look at it again all we did was we provided string input don't worry about the context for now and it returns or anything you put in uppercase so let's do a test so the way you do test is you go here and you configure a test you can have many many tests so that's what you're doing is you're creating a test you're creating your first test let's create a test and this particular test is trying to help you out with is for if for a code that takes JSON and we're not doing that we're doing quote put in double quotes hello it worked in lowercase we're gonna give it a name and say my first test and we're gonna hit create so we just created a test okay now guess what you're my first test is right here we're gonna click on my first test and hit tests guess what it is succeeded we worked right here and so you click the details and so what we typed in was reflected back to us in uppercase as a very simple example you can do way way way more with more with this depending on your imagination but the test worked and that's what's important so let's say we did another test let's show you what it looks like if it didn't work let's do a create new and they have this hello world thing down here and this is the first time I did this it failed and I created test two and I created this test see passing that JSON in there now I pick test two and I run it and guess what it failed and it took me a while to figure this out and but but it tells you what's wrong you need to go through you need to learn how to debug these types of things and it's telling you that the string needs to be quoted and what's really happening is this right here is taking a simple string and it's returning a simple string in what we did and test two is we passed JSON and not that not what it wanted so my first test will pass the second test will not now you can do a lot more with this you can create an API gateway that calls this code it has it can connect to all the other tools out there in Amazon Web Services this is unlimited just because you saw this simple little taste just because you saw this simple little test does not mean that's all it does it does lots and lots more in many different languages so I just connected you to Visual Studio code free and c-sharp in you created a lambda function and you got it to work that's pretty darn cool please like subscribe hit the little alert button if you want more videos like this let me know if you like Amazon Web Services I'll make more of these videos check so check the links below I'll have some relevant book links and if you click on it I get credit credit because I'm an associate good luck and let me know if you liked it
Info
Channel: codingisforyou
Views: 15,390
Rating: undefined out of 5
Keywords: c# lambda vs code, vs code lambda, c# lambda, C# cloud computing, c# lambda code, c# serverless, c# aws, c# aws lambda, serverless, C#, AWS lambda, it operations, devops training, developers, it devel
Id: HeXe0LQSqgI
Channel Id: undefined
Length: 21min 35sec (1295 seconds)
Published: Tue Feb 26 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.