Let's go ahead and build a slightly more complex AWS Lambda function here that accepts a Wikipedia entry, let's say Google or Facebook or Amazon or Netflix, some company, and summarizes the content of the text. The way this works is import JSON here, import Wikipedia, and this particular Lambda function does all the work. You can see here that I use this library, Wikipedia summary after I grab the name of the company that will be summarized, and I say, I want to look at one sentence from Wikipedia and then I return back the response. Pretty straightforward function here. What I'm going to do is I'm going to build a new one inside of this directory, so I'm going to type in sam init to get started. This will go through and ask me, what source would I like to use? I'm going to go through and say 1, a QuickStart template, I'll go through and say I want to create an image artifact, and then for my base installation here, I'm going to choose Amazon Python 3.8 base, so number 4, and then for the project name here I'm going to call this Wikipedia 2021, there we go. It's calling the template, what do we want to build here? Do I want to build Hello World, PyTorch, Scikit-learn, Tensorflow, XGBoost? Let's go ahead and use the Hello World Lambda image inference, start here, and then looks like I'm ready to go if I go into this directory. I'm going to go into this directory here that was created, you can see here it's called Wikipedia 2021, and in the beginning here, you'll see that it created this Hello World directory and all I need to do is double-click this file, and I need to just swap this out with my existing code sample that I have here which is in this AWS Lambda directory. Go ahead and copy this and swap this out into this location. There we go. Looks like we're ready to go here. What's great about this process here is it's really straightforward to test things out and how do we know I can test things out? Well, the first thing that I'm going to do is I'm going to look at this requirements file here. If you notice here there's a docker file, there's requirements file. I'm going to go ahead and put the Wikipedia library, and then in order to test it, I'm going to create a virtual environment, so I'm going to first change it to this directory. Let's go ahead and get in there first and go into the Hello World directory and notice this is where that requirements file is. I'm going to say first Python 3, and we'll say -m, venv. I'm going to create a virtual environment. I like to put them inside my home directory, in a dot directory so that they're hidden and they're far away and they're not going to [inaudible] get checked into a project, and I call it something similar to what I'm creating. We'll just call this wiki. There we go. I'll go ahead and source this, so go source, tilde slash.wiki/bin/activate, and then once I've got this set up, I can do pip install. I can type in pip install -r requirements and this will go through and look at these two requirements files and get this thing cranking. Now if I look at the Read Me, notice that it gives me the instructions about really how to get started here, and so the first thing that I'm going to do is I'm going to say sam build. If I go into this directory here, I could type in sam build and this will show me that I need to be up one level above, not in the actual Lambda directory, I need to be in the template directory, so we'll go and run sam build again, I'll cd up one, and now from here I'm in the right directory, it's going to build out this containerized version of my application, and then what I could do is actually test this out. I can actually go through here and say sam local invoke and this will allow me to invoke this function and notice that it says, "You didn't give me the correct payload." What can I do here to get this thing working? Well, there's a couple ways we could test this. We can either do sam local, or if you remember from our other project. You can also give it the ability to run locally in foreground mode. There's really a couple of different ways that you can get this thing to be invoked, or you also can give it a JSON payload. That's what I'm going to do, is I'm going to basically go inside of here and I'm going to put a JSON payload here. I'm going to say touch, and we'll call this payload.json, like this. I'm going to edit this payload and I'm going to tell it that I want the words entity inside of here, and then we'll put in, let's say for example, google. That looks pretty good. Then if I look at the sam local invoke, so sam invoke and I do help, let's do dash h for help, this should give me, sam, local help. It's giving us sam local invoke -h, and it tells me the different commands that I can run. Let's go ahead and do this. We can see sam local invoke. Here we go. This is what I want, is I want this event here. I'm going to go ahead and say sam local invoke-payload.json. Let's go ahead and try that, sam local invoke -e payload.json. Let's see what happens and it looks like it's close, but we have some an error here. Let's go ahead and try this to be Amazon, let's go ahead and try that. There we go, or another one would be Twitter. We could try that, that might be a better name here. There we go. You can see that when I was able to invoke this with Twitter, it was able to tell me that in fact, this is the first line here. A lot of times when you're first debugging something, you may need to try couple of different payloads and play around with it a little bit and really get a feel for how things work. Now, one little trick that I'll point out here that could be helpful is if I python and try to install here. Notice that it says it's in a virtual environment so I can do a pip install of it and that will put it in my virtual environment. Then what I can do is I can actually use this as a rebel. I'll type in ipython and then I'll say import Wikipedia and then I could say wikipedia.summary and put it in the word google. You should see similar problems like, "Oh, it doesn't match that," but what about Twitter? Does it match the word Twitter and it looks like it does and that's why we're able to get this summary. This is a great way to also Debug things, is to play around with what it would look like from a terminal window. Really we're pretty close here to being able to test this out and deploy it. What I'm going to do is I'm going to, again, look at this README file here that the deploy, that says that do a sam deploy guided. Great, let's go ahead and do that, let's go ahead and deploy this. What do we want to call this? We'll call this wiki2021 and then we'll say US region East perfect. A repository for where we want to put this? I'm going to go over to ECR real quick, and I'm going to make a repository where I could put this inside. Let's go ahead and just maybe put a new one together real quick. We'll just call this one wiki, make that easy. Let's go ahead and create this repo. Select it, which will allow me to select the URI and then go back, and then we'll go ahead and paste that in. There we go. Sure, we want to deploy and just go through and follow the rest of the prompt. This looks good, this looks good, this looks good. Great. It's now building the container and pushing that container to the Amazon Container Registry and then also putting this thing into production. This will be a full web service that will accept a payload that will be adjacent payload. I can test it many different ways. This is really the power of this Cloud9 based deployment, is that I can build this invocation locally, test it out, play around with it, build little tools to talk to it plus invoke it remotely as well. Once this thing is deployed, I'll show the ways that we can go into this and actually test this out. This will take just a second here and then what I'm going to do while this is finishing up the deploy is I'm going to spin up the console for Lambda and find this thing which should be appearing any second now. Once this thing is pushed, it's going to say, waiting for the changeset to be created. Great. We can make this a little bit bigger. You can see all of the different stuff that it's doing. Then it's going to say, great previewing. Do we want to do this? We do.[NOISE] Let's go ahead and say yes. By the way, this is the guided deploy. That's why it's prompting me step-by-step to do this. Now it's going to create the API Gateway. It's also going to deploy the right IAM role and then it's going to put this thing into our production environment. Once we see this in production environment, you'll see that here we go, the creation is in process, it's creating it and we can probably see this as it's getting created if we refresh. There we go, right. So already this thing is created nine seconds ago and it'll start updating it as it's being created so we can see it in real-time, that the window will be completed. There we go. It looks like again, it's working here. Then when it's done, what will happen is, there we go, we can invoke this function remotely. Let's go ahead and refresh this thing real quick. Basically, in order to invoke it, all I would need to do is go to test right here and put in a test payload. In this case, we would say wiki, go through and put in entity, and we'll put in Google, and then this will allow us to invoke this. We should get the same response. It doesn't like Google so we're going to try Twitter. We can put Twitter here and it is able to invoke Twitter successfully. There we go. See Twitter is an American microblogging social network. Perfect. Then again, you can see here that this stack has been created. Here's my production endpoint here. What we can also do now, that it's been deployed is if I go back to this AWS environment and I go down to Lambda, we can look at this last deployment here, which is Wiki. We can scroll here. And if I right-click on it, that I can right-click. Go one more time, don't show again. If I right-click on this thing that we should be able to say invoke on AWS. And then this will allow me to also put in a payload that's similar to what I did remotely. I can type in entity here, for example. Here we go, entity. Then do Twitter and let's see what happens. We can see that I'm able to do that invocation. There we go, and it's able to invoke it remotely. In fact, we can double-check this by trying some other name here. For example, I don't know Pinterest. Let's go ahead and double-check what the name is of Pinterest real quick. Pinterest, okay. I'm going to go ahead and put that in there. Here we go. Let's try that. Pinterest. Let's try this, invoke it, and there you go. It found a new website name. Perfect. Then if I go back to my environment here and I go to the monitor, we should be able to look at the logs and verify that my Cloud9 environment was invoking this function. Let's scroll down. There we go. Pinterest is American image-sharing site. Really this is a round trip feedback loop where you can rapidly develop applications using this SAM-based system with Python. You can deploy it in a production manner, repeatable manner. Maybe the next step would be to put this into a system like AWS code build and do continuous delivery.