AWS node.js relative path to modules

Going mad here folks, please help! I decided to restructure a function into different modules, exactly like the testing guidance gives, to separate the app logic from the provider needs.

However, unless I provide an absolute pathname in the require, sis involve local says can’t find file. Running on AWS I can’t figure how to get it to find the additional module however I specify it. I’ve read the piece on packaging but it doesn’t seem to match, as when I inspect the uploaded zip file on s3, everything I need is there, it just can’t reference it.

I have a function specified in server less.yml as -
handler: functions/aws/licenses/get.get

In this function I have a require(‘validator’) statement (this is the one I’ve been trying with relative paths etc to no avail)

I also have an additional module in validator.js in

Logically, I’d have thought the require statement would be require(’./functions/app/validator’);

I’ve tried every combination I can think of, including this from stack overflow

I’ve probably tied my brain in knots now and need some help!


Managed to make some progress in that I can get this to work in an invoke local but not on AWS.

Within get.js I have

Which references the file in functions/app/validator.js

Works fine with sls invoke local, on AWS it calls out a syntax error on the require statement, any clues please?

This is a voyage of discovery. Invoking the function through sls returns the top line of the error whereas the AWS logs don’t. Turns out I had managed to get the path correct but the stack trace was showing the same errors.

I only found this out by invoking through sls with --log. It also told me the next issue I had was syntax - but code passed all the syntax checks - turns out I’m running node 6 locally and 4 on AWS hence it working locally.

Nearly there, just some issues with ES6 class method invocation to resolve!

1 Like