#100DaysOfWeb in Python Transcripts
Chapter: Days 85-88: Serverless Python with AWS Lambda
Lecture: Uploading a Lambda with external dependencies

Login or purchase this course to watch this video and the rest of the course contents.
0:02 Right so we have our PEP8 checker lambda in place there's only one problem there's no module named pycodestyle and of course we did keep installed
0:17 in our local environment but in our AWS Sandbox it's not there by default so we need to take some extra steps to pip install the module
0:27 in a separate virtual environment zip the package up together with the lambda and upload it as a zip file to AWS. So we're going to run these steps
0:38 to make a lambda zip file including the pycodestyle package and upload that to AWS. So back to my terminal I'm going to deactivate
0:49 my current environment and I'll make a new one. Let's call it AWS. Going to enable it.
1:07 I should not have any packages and I'm going to pip install pycodestyle. And then I need to go into the virtual environment
1:20 lit Python 3.7 side packages folder and I need to do a zip -r nine lambda. Let's call it package zip and let's take this specific pycodestyle files
1:42 and I have to move the zip file up four directories because we are four levels deep. Then I go up and here I have my zip file now
1:58 the only thing I need to do is add the lambda to it and I can use zip -g lambda package.zip and add the lambda we wrote in a previous lesson.
2:11 Now we go back to my lambda and instead of embedding the code that won't work anymore I need to use the upload a zip file option.
2:21 You can also upload it from s three but let's just work with a local zip file for now.
2:41 That's a valid point. My module is called lambda.py so I need to update this as well. Try that again, can still see my code that's not always the case
2:57 but now we have the pycodestyle module there as well. Let's test again with the events we setup. Nice, now it works. Let's do a second event.
3:17 With the famous indentation and test that as well. Awesome, we get output. Now it's time to test the new lambda out
3:29 with our web app but the AWS gateway API is still pointing to the old lambda. So let's fix that first. So go to post, click on integration request
3:48 and we modify the lambda to point to pet checker. Click okay. I believe you need to redeploy.
4:05 All right, let's test it out. Wow, cool. Let's do some real code.
4:31 Let's leave off that second new line. Look at that, expected two lines on line 10. Let's fix that. Let's do some other violation.
4:47 Let's make this a very long line and maybe we have some spaces in a dictionary. Look at that, how cool. That line was indeed too long
5:00 according to PEP 8 and as per PEP 8 we also cannot have white spaces before and after curdecurly braces. Awesome. That concludes the lesson materials.
5:12 We built two lambdas we fully integrated it with AWS and API gateway, you have some interesting code
5:19 you can play with and with that it will be your turn to come in two days and in the next video I will walk you through how you can spend those two days
5:31 getting as much practice as possible. I hope you enjoyed this and see you tomorrow.

Talk Python's Mastodon Michael Kennedy's Mastodon