Deploying AWS Lambda Functions with Docker and Amazon ECR | large 10GB packages (2023)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what is up today I'm gonna be showing you guys how to deploy an AWS Lambo with a bunch of uh dependencies using uh Docker Docker images um ECR and then deploy it to Lambda so uh why would you want to do this well in my last video about deploying Lambda dependencies I used a zip file method and a lot of people are having issues with size of the deployment package like they wanted to deploy a larger size and this method can support several GB 10 gigabytes I believe this will allow you to deploy much larger packages and it's not too much more complicated to do it's actually fairly straightforward so let's get right into that prerequisites for this you need a AWS account you need to have Docker desktop downloaded and you just want to have your AWS CLI configured so if you have all that we're going to run the following uh commands in command line so we'll run this AWS ECR create a repository and then we'll give it a repo name my Lambda repo demo um then we're going to need to create a Docker file so this first part is going to be our python file and then this is the function we're going to be using uh python 3.8 and then we'll just uh pip installs um instead of using a requirements txt I just have directly my dependencies I'm going to pip install so I have request pandas beautiful soup 4 and lxml all right so so then we build our uh doctor image step four is you're going to need to authenticate uh Docker with ECR so you'll have to run this command here you'll insert whatever your region is so it's like you know us East to us West 2 or whatever that region may be and then uh you have your account ID here so if you don't have your account ID you can get this from uh assuming you have the AWS CLS CLI setup you can get this from your in the AWS UI somewhere or you can just run this um command and I'll output the ID for you all right so then we um we we tag the docker image and then we use this push so Docker push um my Lambda repo demo so after that's all done we're pretty much finished and we just need to create a Lambda inside of AWS and we need to make sure that we add um the ECR connection so there's an option when you're creating the Lambda with a Docker image you can select the ECR otherwise if you don't select it you can also in the beginning when you do this they give you some sort of URL that you can paste in there but anyway um pretty straightforward I'm going to actually demo through how to do this now all right so you'll want a new folder here and you want a new folder and you'll need your Docker file so here's my Docker file and then also uh you see we have my Lambda function dot py so you'll need your python file and here's my uh python file it's importing requests pandas and beautiful soup and it's fetching from Wikipedia web scraping page on Wikipedia and then it's getting the references and then we're going to return that which is a data frame so yeah so here's a good like demo function python function that's using a bunch of dependencies all right to go into uh command prompt so let's run uh step one all right so step one run and you'll see you have this repository URI which you uh may need later depending on if you uh just select the path when we create the lam door if you want to copy and paste this this is a repository URI all right so step two create a Docker file so I already showed you the docker file so we are actually already finished step two uh step three build the docker image so let's run this um quick tip you want to have your Docker desktop open if it's not open uh it's not gonna work so make sure that your Docker desktop's installed and on all right so I'm running Docker build all right so since I already ran this command earlier it built pretty quickly otherwise this might take like a minute or two all right so I forgot my account ID so I'm just gonna run this command to get our um get your CLI the account ID right now that we have our account ID we're going to run this with the region and the account ID so I have it set to uses two all right so you should get login succeeded all right so we're almost we're actually already almost finished like you can see how this really isn't that difficult we just need to now uh tag and then we'll have to push it all right so we tag all right to that run and now we need to just do the push all right so when you push you'll see all these like uh pushing so give these a few minutes to run all right so finish pushing so we can close this and let's open up AWS all right so in AWS make sure you're in the same region that you you know you did all the pushing and stuff in um and go to Lambda click on create function all right now out of these options author from scratch used blueprint container image we're going to select container image so we'll give it a name demo Lambda image now in here you can either paste in that URI from earlier when we ran that First Command or you can click browse image and you can just find it so then you have select container image and you can just select a repository and you should see the one that we just made my Lambda repo demo or whatever you named it if you followed along exactly you'll have this name so click that and then select it and click uh select image all right and then just click create function all right so you'll want to next just click on test uh scroll down and just give a new test event it doesn't matter um and then click save and let's click test all right I got an error the first time I ran it but after I just ran it again and it succeeded so click on details and you can see right here we got exactly what we expected status code 200 we have this uh body that looks like it's pulling from Wikipedia so that is it we've successfully deployed a Lambda package using ECR and Docker and uh it really wasn't too hard uh hope you enjoyed thank you
Info
Channel: Tech with Hitch
Views: 1,933
Rating: undefined out of 5
Keywords:
Id: UPkDjhhfVcY
Channel Id: undefined
Length: 8min 22sec (502 seconds)
Published: Tue Aug 29 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.