Web developers tend to use external dependencies (e.g. npm packages) quite often, and lambda functions are not exception - there's no need to reinvent the wheel if we can use a package created by someone else.
In this lesson we're going to learn how to create a Lambda Function Package in order to create and deploy an AWS Lambda function which uses an external dependency - axios
Instructor: [0:00] We have a Lambda function with an API gateway attached to it. I can call this function by going to this API endpoint. What we would like to do is to run this code in our Lambda function.
[0:09] The problem is this code is using an external dependency. I cannot just go ahead and paste this into the AWS console, because it won't work. We need to be able to provide axios as a dependency to our Lambda function.
[0:22] In order to do that, we have to use Lambda function packages. In AWS Lambda, not only we can edit the code in this editor, but we can also upload a zip file containing our code as well as all the dependencies. To create a Lambda function package, we have to zip both the index.js as well as node modules.
[0:38] In order to do that, I'm going to use the zip command, but you can use whatever you want in order to create a zip file. What matter is that we have to include all the code and dependencies inside. I'm going to create this new zip file called lambda_package. Now, let's go ahead and upload it to AWS. Click over here, upload the package, and click save.
[0:56] Now we can see the code that we've just uploaded in this editor over here. There are also all those node modules, including axios, that we are using in order to get a random cat fact. Now if I go over here to our API, and refresh it, I'm going to get a random cat fact.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!