2

Whenever I try to include Twilio module in my Lambda Function, it gives out an error:

"errorMessage": "Cannot find module 'twilio'"

The error is on line:

var client = require('twilio')(accountSid, authToken);

Can anyone help me out with the way we can include modules?

8
  • 1
    Your question seems to be 'Am I including this module correctly?' which could be answered. As a tip, formatting your code as code (wrap in backticks [`]) makes it easier to read. Don't be surprised if someone asks for a more complete code sample. Commented Dec 18, 2015 at 5:09
  • I'm definitely including the module correctly as this is the same procedure as carried out for NodeJs code that runs on local server, and there we install module by using "npm" on terminal window. But in the case of AWS Lambda there is no such terminal window to install the module Commented Dec 18, 2015 at 5:42
  • 1
    Have you included the node_modules folder with your uploaded zip package? I have a separate directory with my lambda node packages and lambda function files. A common gotcha is zipping the directory and not the contents of the directory. So zip -r twilioLambda.zip . when in the directory that holds your lambda function and node modules. Commented Dec 18, 2015 at 6:02
  • I haven't uploaded any zip package. I just wrote the code in the editor provided by AWS Lambda categorised as: "Edit Code Inline". Commented Dec 18, 2015 at 6:08
  • 1
    The reason Lambda can't find the Twilio module is because it sounds like it's not there. Commented Dec 18, 2015 at 16:26

1 Answer 1

5

Twilio developer evangelist here.

There's a really good tutorial on how to include npm modules in Lambda written by the AWS team. It shows how to use Node.js packages in Lambda.

The short version is that you should build your Lambda function locally as you would any other Node.js script, installing the modules as you go into the script. Then, once it is working, zip up your entire directory, including the node_modules directory inside, and use Lambda’s createFunction API, CLI, or the console UI to deploy it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.