In this section, we will explore what more we can do using the Serverless Framework.
When you use the Serverless Framework to deploy your Lambda function, it creates a ZIP file with everything that is inside your project folder. If you need to use a module that is not a Node.js core module or the AWS SDK, you just need to use Node's default workflow to add dependencies.
Take a look at the following steps:
- Create a
package.json
file to store your project dependencies and usenpm install <your-module> --save
to download your required module. - With the
node_modules
folder inside your project directory, the ZIP file will be deployed to AWS with the necessary dependencies. - In the following example, the Lambda function of the file
handle.js
uses an npm module calledcat-names
:
module.exports.catNames = (event, context, callback) => {
const catNames = require('cat-names');
const response = {
statusCode: 200,
...