Issue setting up Lambda with API gateway

I have been trying to set up an api to access twitter data from AWS Lambda and can’t get past authentication. I’m being given the following error message when testing my code and hoping someone here can help..

{
“errorMessage”: “Cannot find module ‘sshpk’”,
“errorType”: “Error”,
“stackTrace”: [
“Function.Module._load (module.js:417:25)”,
“Module.require (module.js:497:17)”,
“require (internal/module.js:20:19)”,
“Object. (/var/task/node_modules/http-signature/lib/utils.js:4:13)”,
“Module._compile (module.js:570:32)”,
“Object.Module._extensions..js (module.js:579:10)”,
“Module.load (module.js:487:32)”,
“tryModuleLoad (module.js:446:12)”,
“Function.Module._load (module.js:438:3)”,
“Module.require (module.js:497:17)”,
“require (internal/module.js:20:19)”,
“Object. (/var/task/node_modules/http-signature/lib/parser.js:5:13)”,
“Module._compile (module.js:570:32)”,
“Object.Module._extensions..js (module.js:579:10)”,
“Module.load (module.js:487:32)”
]
}

Hopefully I’ve included enough info to make sense appologies if not, this is the first time I’ve tried accessing anything other than from S3


Related discussions:

Sorry I just want to add as well that I have the code running successfully on an EC2 instance that I can run through ssh in the terminal

Are you packaging your dependencies with your function for Lambda?
Looks like your function wants sshpk. You’ll need to pkg that dependency accordingly.

You likely installed some stuff on your ec2 instance or had pre-built stuff on it. You’ll want to find the necessary things you need, and package them alongside your lambda function and upload the zip.

Yes I included the same package.json in my zip file as I had set up on my ec2., I just grabbed all the files from there and that was what I sent to lambda. So are you saying I should redo my package.json locally and include that one instead?

You have to install the stuff in package.json locally and zip them up. Should install into a “vendor” directory. You need to do research on getting your dependencies packaged onto lambda.

Thanks, yeah I’ve been watching videos on it for a while and reading aws documentation. I just couldn’t figure out why it worked on my EC2 but failed on lambda. Thanks for the info, I’m brand new to this so there’s a lot about aws I need to read up on. I’ll start again and see how I get on