Let's dive into building an AWS Lambda function that returns back a result through API Gateway. To get started, I'm going to go to a repo, noahgift AWS Lambda here, and I'm going to clone this. Go ahead and copy that and type in git clone. Notice that, it said I can't connect because I don't have SSH key. I'm going to go ahead and create those SSH keys. Ssh-keygen -t rsa, press return a few times, and then I can actually print out this public key here to give it to GitHub. I'm going to go through and say, cut, paste that out, and I'm going to grab this whole block of text up to the end here, which is ssh-rsa. Next, I'll go over to my GitHub profile and I will select Settings here. If I go ahead and select Settings, I've already got it open, I can scroll down to SSH and GPG keys, create a new one, we'll call this awslambadev. Here we go, paste that in, and it'll ask for my password. Now that it's set up, I can go back here and actually just type in the up arrow until I get to that command, and then clone it. Now what I want to do is cd into this AWS Lambda directory, because there's a script here that may or may not be useful depending on how much you use your Lambda environment. Notice it's called resize here, and in particular, if you type in df -h, it will show you that, there's only a couple of gigs available by default with AWS Lambda on Cloud 9 when you're developing. If you run this resize command, if I say chmod +x, and then run it, what will happen is that it'll resize the disk to be a 20 gig disk. It gives me a little bit more room for work where I would be using things like Containers which can take up a lot of room. Now if I run this df -h command again, notice that there's a lot more room. This is just a nice trick to be aware of, and it's something you can get from this repo. Now, the next thing I'm going to do to get started here is, I'm going to run a command called sam init, and if I type in sam I-N-I-T, this will actually initialize a new Lambda function for me. I'm going to go ahead and say, yes, I want to do that, I want to do a quick start template, so I'll select one, and then which package would you like to build? Either a zip, an artifact is a zip uploaded to S3 or an image artifact is an image uploaded to an ECR image repository. Now with this one, this is actually a containerized version of a Lambda, and it would live in Elastic Container Registry. I'm going to go ahead and select two here, and then notice it gives me some options for base images. What do I want to do? There's lots of different programming languages. I'm going to select four here, if we scroll down here, you can see there's several options. I'm going to select Amazon python 3.8 base. Go ahead and select that. Then what do we want to call this? Let's go ahead and call this Hello World Lambda, and we'll call this 2021. There we go, and it's going to go through and give me some additional information here. Do I want to quick start, let's say maybe a scikit-learn project, which is pretty neat or do I want to go through and build just a regular hello world application? I'm going to go through here and say Hello World Lambda image application. There we go. Then the next steps can be read out here in a README file. Here we go. I'm going to go to these next steps here inside of this project. Let's go ahead and look at this. If I go to this Hello World Lambda project, you can see there's a README that goes through and tells me step-by-step what I need to do. These might change slightly in the future, there might be slightly different versions, but sam init is a great way to get started. I'm going to go through, and just do exactly what it says. It's going to say Sam Build. Let's go ahead and run that first. I'm going to cd into this directory that I created, and then I'm going to type in Sam Build. There we go, and now it's going to go through and it's going to dockerize a Lambda environment for me, and what's great about this is, I can even test things locally by using this new containerized workflow for AWS Lambda. So really you can think of a container as a way of emulating what's going to happen in production. There we go, we've got this thing created. Now, if I want to look at the actual application here itself is going to be inside of this, this Hello World, and notice here that, it really is a very simple application that just basically returns back hello world. If I wanted to change this, I could change this into other things, but here we go. We've got this Hello World application, and now if I want to invoke it, I can do what it says, I can say sam local invoke. This will actually go through here and test this out. It'll give me the ability to invoke it. There we go. We can see that it actually called it. We're done in a sense, in testing this locally, so the next step would be to do a deploy. Let's go ahead and scroll back through here, and see how we would do this. Well, what I could do is, I could say sam deploy --guided. I'm going to go ahead and do that. I'm going to say sam deploy --guided. Then this will go through and ask me what I want to call this stack. We'll again call this Hello World stack, maybe 2021. Then it'll ask me to select the region, we'll say US East, that's good. Image repository. Sure, let's go ahead and use that, leave the default here for image repository for HelloWorldFunction. Now, notice that it will actually want me to give it a location to put this containerized image. What I can do is actually go to the Container Registry here real quick and create a new repo just for this and we'll just call this HelloWorldRepo like that. Let's go ahead and create this repository. By the way it doesn't want uppercase so I'll go ahead and change that, we'll just say helloworldrepo. There we go and we'll scroll down here and there we go. I can just copy this URI, or copy the repository name, let's go ahead and try that. We'll say does that work? It doesn't like that one so let's go ahead and do it again. This time we'll put in the full URI, I'll go ahead and copy this and from here again, we can just say HelloWorld2021. Go through here, paste this in, are you sure you want to deploy? Yeah, we'll go ahead and do that. Allow SAM to create the necessary permissions, we'll go ahead and do that. That's fine, we don't care about authentication and then also we want to save the arguments to a file, and then create this config file. There we go. Basically what's happening now is it's taking this local container and it's pushing it to the Amazon Container Registry. Then once we do this, it will then be able to deploy it from that containerized environment. Let's go ahead and watch this thing in action, and this is also one of the great things about using the Cloud9 environment is that allows me to have fast interaction between services that are in AWS. In particular, inside of AWS, you're able to push your code into a new environment, go through and get access to really datacenters or datacenters speed because it's not my laptop which could be, let's say on a wireless network or something like that. It looks like it's getting close to being done here, there we go push. Now notice that it's uploading this now to the final location. It's putting these final changes here perfect and it says, do you really want to deploy? If we scroll out and look at the output, you can see it's using a Infrastructure as Code service called CloudFormation to deploy it. Yes, we want to deploy this change and what will happen is that after this goes through and deploys, I can actually go through and look at that Lambda application in production as well. That's one of the useful things about using this hole in the end feedback loop is that it really solves the production deployment aspect of deploying a Lambda function. This really is using best practices from AWS, they're all combined inside of this tool and then it goes through and just with a couple of commands allows you to deploy this to production. Once this is deployed, what will happen is I'll be able to invoke it by using this tool over here, AWS Explorer, and also I'll be able to invoke it by using the function itself in AWS Lambda. Notice that it's available now with API Gateway, it's hooking up all these final components. Let's give this just a second longer here and then what will happen is that I'll be able to test it out. Now notice here that it gave me this end point. If I just scroll here because again it's a get function that just returns back a result, we can actually curl this and it will return back payload for us. There we go. We can see that HelloWorld is working and even if I put this into a web browser as well, you can see there we go, hello world. We've been able to go full and in to deploy it, if we want to look at it inside of the AWS environment, I can also go to that Lambda function and we should be able to see it as well. There we go, there's a HelloWorldFunction, it's been deployed, you can see it's been last modified and I can actually invoke it if I wanted to directly inside of here. If I go through here and just give it an empty payload that doesn't accept anything, we can actually say invoke, and notice that it says the same thing. It says HelloWorld and even further, notice that here's the trigger, this API Gateway trigger is that it'll give me the URL as well. I can invoke it that way yet one more way to invoke it is again, if I go to AWS here, and I go to Lambda, I could go through and find that HelloWorldFunction and invoke it. I think it's here here we go, Hello, World 2021, if I right-click, I can say invoke on AWS and notice that it gives me back this neat little widget here, and I can say do I want to give it anything? No, we don't care just invoke it, there we go. We can see that it works. There's several ways to test your Lambda function including basically built-in integration into the terminal. Personally, I like the command line, I think that's one of the better ways to test a HelloWorld application.